Resource | Purpose |
SDKAppID, client key (Push Key) | Call registerPush |
timpush-configs.json | Place in the Android app module assets |
Target manufacturer config files (if any) | Place Google FCM and other manufacturer files in the project as required |
Project applicationId | Must match the package name on the manufacturer platform |
TIMPush version VERSION |
Resource | Purpose |
SDKAppID, Push Key | Call registerPush |
Certificate ID ( businessID / apnsCertificateID) | Generated after you upload the APNs certificate in the console; pass it via registerPush |
App Group ID (optional) | Required only for reach statistics; pass via applicationGroupID in registerPush |
VERSION, SDKAppID, AppKey, certificate ID, and App Group ID are placeholders. Do not commit real keys to your code repository.pubspec.yaml, or run the following command to install it automatically:flutter pub add tencent_cloud_chat_push
com.tencent.timpush:timpush / tuicore again. Only add the target manufacturer channel packages as needed.TencentCloudChatPushApplication.android/app/build.gradle or android/app/build.gradle.kts, add the TIMPush channel packages for your target manufacturers as needed. Native push for a manufacturer is enabled only after you add the corresponding package. Get VERSION from the Release Notes and replace it with the actual version number.dependencies {implementation 'com.tencent.timpush:fcm:VERSION'}
dependencies {implementation("com.tencent.timpush:fcm:VERSION")}
Application class and extend TencentCloudChatPushApplication. If your project already has a custom Application, change it to extend this class and make sure onCreate() calls super.onCreate().package com.example.pushdemoimport com.tencent.chat.flutter.push.tencent_cloud_chat_push.application.TencentCloudChatPushApplicationclass MyApplication : TencentCloudChatPushApplication() {override fun onCreate() {super.onCreate()}}
android:name on the <application> tag in android/app/src/main/AndroidManifest.xml to point to the custom Application class above.<applicationandroid:name=".MyApplication"...></application>
ios/Runner/AppDelegate.swift to return the push certificate ID and App Group ID, and to forward offline push click events. The certificate ID and App Group ID are passed via registerPush, then returned to TIMPush through the bridge methods below.import 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 func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {GeneratedPluginRegistrant.register(with: self)return super.application(application, didFinishLaunchingWithOptions: launchOptions)}// Add this function@objc func businessID() -> Int32 {return TencentCloudChatPushFlutterModal.shared.businessID();}// Add this function@objc func applicationGroupID() -> String {return TencentCloudChatPushFlutterModal.shared.applicationGroupID()}// Add this function@objc func onRemoteNotificationReceived(_ notice: String?) -> Bool {TencentCloudChatPushPlugin.shared.tryNotifyDartOnNotificationClickEvent(notice)return true}}
registrationID for the device. The server, Console Access Test, and troubleshooting tools can use this identifier to send offline pushes to the device. If the app also integrates Chat and completes login, you can also use userID to send offline pushes to devices that have established a push relationship for that user.appKey affects the registration method and available push identifiers:appKey = Push Key: Register TIMPush standalone push. Push Key is the client key.appKey = null: Reuse the Chat login state to register for push. You must call this after a successful Chat login.userID and registrationID push relationships become invalid and must be registered again.appKey for registerPush.main method. We recommend calling it after the user agrees to the privacy policy, at an appropriate time on the business side.Future<void> registerTIMPush() async {final push = TencentCloudChatPush();final registerRes = await push.registerPush(// TODO: Replace with your SDKAppID.sdkAppId: 0,// TODO: Replace with the Push client key.appKey: '<#YOUR_PUSH_APP_KEY#>',// iOS: Replace with the certificate ID generated in the Tencent Cloud console; not required on Android.apnsCertificateID: 0,// iOS optional: To measure push reach, replace with the App Group ID configured in Apple Developer Center or Xcode; not required on Android.// applicationGroupID: 'group.<#YOUR_APP_GROUP_ID#>',// The current Flutter API still requires this parameter, but the callback is to be deprecated.// Do not handle notification clicks here; use addPushListener instead.onNotificationClicked:({required String ext, String? userID, String? groupID}) {},);if (registerRes.code != 0) {debugPrint('registerPush failed: code=${registerRes.code}, ''msg=${registerRes.errorMessage}, deviceToken=${registerRes.data}',);return;}final ridRes = await push.getRegistrationID();debugPrint('registerPush success, registrationID=${ridRes.data}, ''code=${ridRes.code}, msg=${ridRes.errorMessage}',);}
Future<void> loginIMAndRegisterPush() async {final int sdkAppId = 0; // TODO: Replace with your SDKAppID.final String userID = '<#YOUR_USER_ID#>';final String userSig = '<#YOUR_USER_SIG#>';final initRes = await TencentImSDKPlugin.v2TIMManager.initSDK(sdkAppID: sdkAppId,);if (initRes.code != 0) {debugPrint('initSDK failed: code=${initRes.code}, desc=${initRes.desc}');return;}final loginRes = await TencentImSDKPlugin.v2TIMManager.login(userID: userID,userSig: userSig,);if (loginRes.code != 0) {debugPrint('login failed: code=${loginRes.code}, desc=${loginRes.desc}');return;}final push = TencentCloudChatPush();final registerRes = await push.registerPush(sdkAppId: sdkAppId,// iOS: Replace with the certificate ID generated in the Tencent Cloud console; not required on Android.apnsCertificateID: 0,// iOS optional: To measure push reach, replace with the App Group ID configured in Apple Developer Center or Xcode; not required on Android.// applicationGroupID: 'group.<#YOUR_APP_GROUP_ID#>',// The current Flutter API still requires this parameter, but the callback is to be deprecated.// Do not handle notification clicks here; later sections introduce the recommended listener approach.onNotificationClicked:({required String ext, String? userID, String? groupID}) {},);if (registerRes.code != 0) {debugPrint('registerPush failed: code=${registerRes.code}, ''msg=${registerRes.errorMessage}, deviceToken=${registerRes.data}',);return;}final ridRes = await push.getRegistrationID();debugPrint('registerPush after login success, registrationID=${ridRes.data}, ''code=${ridRes.code}, msg=${ridRes.errorMessage}',);}
registerPush before Chat login. Otherwise the SDK may register a Push-type account as in the standalone push scenario and generate corresponding Push DAU. Extra charges may apply if Push DAU exceeds the package quota.mutable-content, App Group, and related configuration.applicationGroupID when calling registerPush.applicationGroupID() is implemented in ios/Runner/AppDelegate.swift.TIMPush keyword to check registration. After successful registration, call getRegistrationID() to get the current device push identifier. When sending a test message from the console or server, you can use this value to target the device.registrationID or userID to send an offline push test.Future<void> sendTestPushMessage({required String targetUserID,}) async {final createRes = await TencentImSDKPlugin.v2TIMManager.v2TIMMessageManager.createTextMessage(text: 'Hello TIMPush');final message = createRes.data?.messageInfo;if (createRes.code != 0 || message == null) {debugPrint('createTextMessage failed: code=${createRes.code}');return;}final sendRes = await TencentImSDKPlugin.v2TIMManager.v2TIMMessageManager.sendMessage(message: message,receiver: targetUserID,groupID: '',priority: MessagePriorityEnum.V2TIM_PRIORITY_NORMAL,onlineUserOnly: false,offlinePushInfo: OfflinePushInfo(title: 'Push title',desc: 'Push content',ext: '{"action":"open_chat","conversationID":"c2c_$targetUserID"}',),);debugPrint('sendMessage result: code=${sendRes.code}, desc=${sendRes.desc}, ''msgID=${sendRes.data?.msgID}',);}
OfflinePushInfo.ext when sending a message. Example:Future<void> sendMessageWithPushExt({required String targetUserID,}) async {final createRes = await TencentImSDKPlugin.v2TIMManager.v2TIMMessageManager.createTextMessage(text: 'Hello TIMPush');final message = createRes.data?.messageInfo;if (createRes.code != 0 || message == null) {debugPrint('createTextMessage failed: code=${createRes.code}');return;}final sendRes = await TencentImSDKPlugin.v2TIMManager.v2TIMMessageManager.sendMessage(message: message,receiver: targetUserID,groupID: '',priority: MessagePriorityEnum.V2TIM_PRIORITY_NORMAL,onlineUserOnly: false,offlinePushInfo: OfflinePushInfo(title: 'Push title',desc: 'Push content',ext: '{"conversationID":"$targetUserID","conversationType":1}',),);debugPrint('sendMessage result: code=${sendRes.code}, desc=${sendRes.desc}, ''msgID=${sendRes.data?.msgID}',);}
TencentCloudChatPush().addPushListener to listen for notification click events and parse ext in onNotificationClicked. Example:final TIMPushListener timPushListener = TIMPushListener(onRecvPushMessage: (TimPushMessage msg) {debugPrint('onRecvPushMessage: title=${msg.title}, desc=${msg.desc}, ''ext=${msg.ext}, msgID=${msg.messageID}',);},onRevokePushMessage: (String msgID) {debugPrint('onRevokePushMessage: msgID=$msgID');},onNotificationClicked: (String ext) {debugPrint('onNotificationClicked: ext=$ext');// 1. Parse ext. The JSON structure is defined by your business and must match the sender.Map<String, dynamic>? extJson;try {extJson = jsonDecode(ext) as Map<String, dynamic>;} catch (e) {debugPrint('parse ext failed: $e');return;}final String? conversationID = extJson['conversationID'] as String?;final int? conversationType = extJson['conversationType'] as int?;if (conversationID == null || conversationType == null) {return;}// 2. TODO: Navigate to the target page based on business fields.// If you use Chat / TUIKit, navigate after the user logs in successfully;// for cold start, cache the parameters first and navigate in the login callback.},);Future<void> addTIMPushListener() async {await TencentCloudChatPush().addPushListener(listener: timPushListener);}Future<void> removeTIMPushListener() async {await TencentCloudChatPush().removePushListener(listener: timPushListener);}
TencentCloudChatPush().registerPush still requires the onNotificationClicked parameter, but it is to be deprecated. For new integrations, do not handle redirects in registerPush’s onNotificationClicked; use addPushListener instead.ext is a business passthrough field written by the sender. We recommend a JSON string, for example {"conversationID":"user_A","conversationType":1}.listener as early as possible—for example after login completes and before the business home page initializes.Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan