English | 简体中文
For the overview and console prerequisites (create an app / obtain keys / enable push and configure vendor channels), please read the parent document first: ../README.md. This document focuses only on the React Native client-side integration.
The Tencent Cloud TIMPush offline-push React Native experience demo. This project is a clean template with nothing configured: the SDKAppID, AppKey, Android vendor channels, and iOS signing / certificate ID all need to be configured by you as described below before it can build and run.
- You have completed the Common Prerequisites (Console) in the parent document, obtained the SDKAppID / AppKey, and enabled push and configured the vendor offline channels you need in the console.
- Node.js (
>= 18), the React Native environment, plus Android Studio / Xcode + CocoaPods, and a real device is ready (push must be verified on a real device).
cd react-native
npm install
# iOS additionally
cd ios && pod install && cd ..The push plugin is declared in package.json:
"@tencentcloud/react-native-push": "^1.4.0"Open App.tsx and change the placeholders to the actual values obtained in the Prerequisites:
const SDK_APP_ID = 0; // change to your SDKAppID
const APP_KEY = ''; // change to your AppKey- The entry class
MainApplication.ktextendsTencentCloudPushApplication, andandroid/app/src/main/AndroidManifest.xmlpointsandroid:nameto it. - Add the vendor maven repositories and classpath in
android/build.gradle, and enable the vendor channels you need inandroid/app/build.gradle(Xiaomi / Huawei / Honor / OPPO / vivo / Meizu / FCM). - Place the vendor config files:
timpush-configs.json→android/app/src/main/assets/- Huawei
agconnect-services.json→android/app/src/main/assets/ - FCM
google-services.json→android/app/(not assets) - Honor
mcs-services.json→android/app/(not assets)
- Fill Honor / vivo
manifestPlaceholdersinandroid/app/build.gradle.
- Open
ios/PushDemo.xcworkspacewith Xcode (not the.xcodeproj). - In
Signing & Capabilities, add thePush Notificationscapability and configure signing / Bundle ID. - Fill the APNs certificate ID into
timpush-configs.jsonunderios/.../Resources/.
npm run android
# or
npm run iosConnect a real device and run. After registration succeeds, the UI displays the RegistrationID; receiving a push means the whole flow works.
App.tsx: demonstratesregisterPush/unRegisterPush/getRegistrationID/setRegistrationID, and listens toNOTIFICATION_CLICKED/MESSAGE_RECEIVED/MESSAGE_REVOKEDviaaddPushListener.setRegistrationIDonly takes effect when called beforeregisterPush.- If you have integrated IM and call
registerPushafter IM login succeeds, passappKeyas null to avoid kicking the IM account offline.