
implementation 'com.tencent.timpush:timpush:VERSION'implementation 'com.tencent.liteav.tuikit:tuicore:latest.release'
int sdkAppId = 0; // Your sdkAppIdString appKey = ""; //Client secretTIMPushManager.getInstance().registerPush(context, sdkAppId, appKey, new TIMPushCallback() {@Overridepublic void onSuccess(Object data) {}@Overridepublic void onError(int errCode, String errMsg, Object data) {}});
TIMPushManager.getInstance().addPushListener(new TIMPushListener() {@Overridepublic void onNotificationClicked(String ext) {Log.d(TAG, "onNotificationClicked =" + ext);// Getting ext for Definition redirect}});
// Dynamic Broadcast RegistrationIntentFilter intentFilter = new IntentFilter();intentFilter.addAction(TUIConstants.TIMPush.NOTIFICATION_BROADCAST_ACTION);LocalBroadcastManager.getInstance(context).registerReceiver(localReceiver, intentFilter);// Broadcast Receiverpublic class OfflinePushLocalReceiver extends BroadcastReceiver {public static final String TAG = OfflinePushLocalReceiver.class.getSimpleName();@Overridepublic void onReceive(Context context, Intent intent) {DemoLog.d(TAG, "BROADCAST_PUSH_RECEIVER intent = " + intent);if (intent != null) {String ext = intent.getStringExtra(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);// Getting ext for Definition redirect} else {Log.e(TAG, "onReceive ext is null");}}}
target 'YourAppName' do# Uncommment the next line if you're using Swift or would like to use dynamic frameworksuse_frameworks!use_modular_headers!# Pods for Examplepod 'TXIMSDK_Plus_iOS_XCFramework'pod 'TIMPush', 'VERSION'end
pod install# If you cannot install the latest version of TUIKit, run the following command to update your local CocoaPods repository list.pod repo update
const int sdkAppId = 0; // Your sdkAppIdstatic const NSString *appKey = @""; // Client secret key[TIMPushManager registerPush:sdkAppId appKey:appKey succ:^(NSData * _Nonnull deviceToken) {} fail:^(int code, NSString * _Nonnull desc) {}];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[TIMPushManager addPushListener:self];return YES;}#pragma mark - TIMPushListener- (void)onNotificationClicked:(NSString *)ext {// Getting ext for Definition redirect}
- onRemoteNotificationReceived method in the AppDelegate.m file.#pragma mark - TIMPush- (BOOL)onRemoteNotificationReceived:(NSString *)notice {//- If YES is returned, TIMPush will not execute the built-in TUIKit offline push parsing logic, leaving it entirely to you to handle.//NSString *ext = notice;//OfflinePushExtInfo *info = [OfflinePushExtInfo createWithExtString:ext];//return YES;//- If NO is returned, TIMPush will continue to execute the built-in TUIKit offline push parsing logic and continue to callback - navigateToBuiltInChatViewController:groupID: method.return NO;}
tencent_cloud_chat_push. You can include it in your pubspec.yaml dependency directory, or install it automatically with the following command.flutter pub addtencent_cloud_chat_push
void _onNotificationClicked({required String ext, String? userID, String? groupID}) {print("_onNotificationClicked: $ext, userID: $userID, groupID: $groupID");if (userID != null || groupID != null) {// Navigate to the corresponding Message Page based on userID or groupID.} else {// Use your own parsing method based on the ext field to navigate to the corresponding page.}}TencentCloudChatPush().registerPush(onNotificationClicked: _onNotificationClicked, sdkAppId: Your sdkAppId, appKey: "Client secret key");
Replace "package" with your own package name (usually auto-generated by Android Studio)import com.tencent.chat.flutter.push.tencent_cloud_chat_push.application.TencentCloudChatPushApplication;public class MyApplication extends TencentCloudChatPushApplication {@Overridepublic void onCreate() {super.onCreate();}}
extend TencentCloudChatPushApplication and ensure that the onCreate() function calls super.onCreate();.The AppDelegate class inherits from TIMPushDelegateimport UIKitimport Flutter// Add these two import linesimport TIMPushimport tencent_cloud_chat_push// Add `, TIMPushDelegate` to the following line@UIApplicationMain@objc class AppDelegate:FlutterAppDelegate,TIMPushDelegate{override funcapplication(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?)->Bool{GeneratedPluginRegistrant.register(with:self)returnsuper.application(application,didFinishLaunchingWithOptions:launchOptions)}// Add this functionfuncofflinePushCertificateID()->Int32{returnTencentCloudChatPushFlutterModal.shared.offlinePushCertificateID();}// Add this functionfuncapplicationGroupID()->String{returnTencentCloudChatPushFlutterModal.shared.applicationGroupID()}// Add this functionfunconRemoteNotificationReceived(_ notice:String?)->Bool{TencentCloudChatPushPlugin.shared.tryNotifyDartOnNotificationClickEvent(notice)returntrue}}



registerPush, you can obtain the push ID identifier, RegistrationID, through getRegistrationID. You can push messages to specified devices based on RegistrationID.// Integration of TencentCloud-Pushimport * as Push from '@/uni_modules/TencentCloud-Push';const SDKAppID = 0; // Your SDKAppIDconst appKey = ''; // Client secret keyPush.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 and obtain push extension information.Push.addPushListener(Push.EVENT.NOTIFICATION_CLICKED, (res) => {// res is the push extension infoconsole.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 revocationPush.addPushListener(Push.EVENT.MESSAGE_REVOKED, (res) => {// res is the revoked message IDconsole.log('message revoked', res);});


npx @react-native-community/cli@latest init MyReactNativeApp --version 0.75.0
npm install @tencentcloud/react-native-push --save
App.tsx and replace SDKAppID and appKey with your application's information.import Push from '@tencentcloud/react-native-push';const SDKAppID = 0; // Your SDKAppIDconst appKey = ''; // Client secret keyif (Push) {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 and obtain push extension information.Push.addPushListener(Push.EVENT.NOTIFICATION_CLICKED, (res) => {// res is the push extension infoconsole.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);});}
MyReactNativeApp/android directory using 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;}...}
File > Sync Project with Gradle Files.MyReactNativeApp/ios/MyReactNativeApp.xcworkspace using XCode.MyReactNativeApp/ios directory and install TIMPush.pod install# If you cannot install the latest version,# execute the following command to update the local CocoaPods repository list.pod repo update


npm run android
npm run ios

Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan