npx @react-native-community/cli@latest init MyReactNativeApp --version 0.75.0
@tencentcloud/react-native-push.npm install @tencentcloud/react-native-push --save
yarn add @tencentcloud/react-native-push
App.tsx, and replace SDKAppID and appKey with the application information from Console> Push > App Push > Overview.registerPush succeeds, you can use getRegistrationID to get the push ID, that is, RegistrationID. You can send messages to a specific RegistrationID.
import Push from '@tencentcloud/react-native-push';const SDKAppID = 0; // Your SDKAppIDconst appKey = ''; // AppKeyif (Push) {// If you need to associate with the Chat login userID (to push messages to this userID), use setRegistrationID// Push.setRegistrationID(userID, () => {// console.log('setRegistrationID ok', userID);// });Push.registerPush(SDKAppID, appKey, (data) => {console.log('registerPush ok', data);Push.getRegistrationID((registrationID) => {console.log('getRegistrationID ok', registrationID);});}, (errCode, errMsg) => {console.error('registerPush failed', errCode, errMsg);});// Listen for notification bar click events to get push extension informationPush.addPushListener(Push.EVENT.NOTIFICATION_CLICKED, (res) => {// res is the push extension informationconsole.log('notification clicked', res);});// Listen for online pushPush.addPushListener(Push.EVENT.MESSAGE_RECEIVED, (res) => {// res is the message contentconsole.log('message received', res);});// Listen for online push recallPush.addPushListener(Push.EVENT.MESSAGE_REVOKED, (res) => {// res is the recalled message IDconsole.log('message revoked', res);});}
timpush-configs.json file from the Console and add it to MyReactNativeApp/android/app/src/main/assets. If the directory does not exist, create it manually. As shown below:

google-services.json file under MyReactNativeApp/android/app, as shown below:MyReactNativeApp/android/app/src/main/assets" directory).

MyReactNativeApp/ios/MyReactNativeApp, create a Resources folder and a timpush-configs.json file. Edit timpush-configs.json and enter the certificate ID from the Console, as shown below:{"businessID": "Your certificate ID"}

timpush-configs.json to the project. As shown below:
timpush-configs.json matches the applicationId in MyReactNativeApp/android/app/build.gradle. If they do not match, offline push will not work.MyReactNativeApp/android directory in Android Studio....import com.tencent.qcloud.rntimpush.TencentCloudPushApplication// Replace Application with TencentCloudPushApplicationclass MainApplication : TencentCloudPushApplication(), ReactApplication {...// add TencentCloudPushPackage to the list of packages returned in ReactNativeHost's getPackages() methodoverride fun getPackages(): List<ReactPackage> =PackageList(this).packages.apply {// Packages that cannot be autolinked yet can be added manually here, for example:// add(MyReactNativePackage())}}
...import com.tencent.qcloud.rntimpush.TencentCloudPushApplication;// Replace Application with TencentCloudPushApplicationpublic class MainApplication extends TencentCloudPushApplication implements ReactApplication {...// add TencentCloudPushPackage to the list of packages returned in ReactNativeHost's getPackages() method@Overrideprotected List<ReactPackage> getPackages() {List<ReactPackage> packages = new PackageList(this).getPackages();// Packages that cannot be autolinked yet can be added manually here, for example:// packages.add(new MyReactNativePackage());return packages;}...
android/build.gradle to update repositories, dependencies, and allprojects.buildscript {...repositories {...google()mavenCentral()maven { url 'https://mirrors.tencent.com/nexus/repository/maven-public/' }}dependencies {...// If com.android.tools.build:gradle in your project has no version number, set it to 8.5.0// classpath("com.android.tools.build:gradle:8.5.0")classpath 'com.google.gms:google-services:4.3.15'}}allprojects {repositories {mavenCentral()maven { url 'https://mirrors.tencent.com/nexus/repository/maven-public/' }}}...
android/app/build.gradle to configure manufacturer push packages as needed and apply plugins....// If your app needs FCM push, uncomment the next line// apply plugin: 'com.google.gms.google-services'...android {...defaultConfig {...manifestPlaceholders = []}}dependencies {...// Add manufacturer push packages as needed. Native push for a manufacturer is enabled only after you add the corresponding package.implementation 'com.tencent.timpush:fcm:8.5.6864'}
MyReactNativeApp/ios directory and install TIMPush.pod install# If you cannot install the latest version, run the following command to update the local CocoaPods repo listpod repo update
npm run android
npm run ios
フィードバック