Quick Start
Step 1: Activate the Push Service
Before proceeding, please refer to the Service Activation documentation to either obtain a trial version of the Push service or purchase a paid subscription package.
Step 2: Integrate TIMPush and register for push notifications
Note:
The parameters required for the registration interface, sdkAppId and client key appKey, can be obtained from: Console > Push Basic information, as shown in the screenshot below:
1. Integration of TIMPush
implementation 'com.tencent.timpush:timpush:VERSION'implementation 'com.tencent.liteav.tuikit:tuicore:latest.release'
2. Registration for push notifications (after successful registration, you can receive online push notifications)
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) {}});
Note:
1. After successfully registering for offline push service, you can obtain the unique push ID, RegistrationID, through the getRegistrationID interface. Then, you can push messages to the specified device based on the RegistrationID.
2. RegistrationID is the unique push ID of the device. It is automatically generated after successfully registering for push service by default, but it also supports user-defined settings. It allows users to push messages to the specified device based on the RegistrationID. Reinstalling the app will change it, so it needs to be called before registering for push service.
String registrationID = ""; //Push ID, needs to be called before registering for push serviceTIMPushManager.getInstance().setRegistrationID(registrationID, new TIMPushCallback() {@Overridepublic void onSuccess(Object data) {}@Overridepublic void onError(int errCode, String errMsg, Object data) {}});
3. Implement click notification bar callback
After receiving the push message, clicking the notification bar will trigger the component to callback the click event and pass through the offline message.
Note:
It is recommended to place the registration callback timing in the onCreate() function of the application.
TIMPushManager.getInstance().addPushListener(new TIMPushListener() {@Overridepublic void onNotificationClicked(String ext) {Log.d(TAG, "onNotificationClicked =" + ext);// Getting ext for Definition redirect}});
The component will notify the application in the form of a callback or broadcast, and the application can configure the app's page jump in the callback.
Note:
It is recommended to place the registration callback timing in the onCreate() function of the application.
// 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");}}}
1. Integration of TIMPush
Supports CocoaPods integration. You need to add the component dependencies in the Podfile.
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
Run the following command to install the TIMPush component.
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
2. Registration for push notifications (after successful registration, you can receive online push notifications)
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) {}];
Note:
1. After successfully registering for offline push service, you can obtain the unique push ID, RegistrationID, through the getRegistrationID interface. Then, you can push messages to the specified device based on the RegistrationID.
2. RegistrationID is the unique push ID of the device. It is automatically generated after successfully registering for push service by default, but it also supports user-defined settings. It allows users to push messages to the specified device based on the RegistrationID. Reinstalling the app will change it, so it needs to be called before registering for push service.
NSString registrationID = @""; // Push ID, needs to be called before registering for push service[TIMPushManager setRegistrationID:registrationID callback:^{}];
3. Implement click notification bar callback
After receiving the push message, clicking the notification bar will trigger the component to callback the click event and pass through the offline message.
Note:
It is recommended to place the registration callback timing in the didFinishLaunchingWithOptions function of the AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[TIMPushManager addPushListener:self];return YES;}#pragma mark - TIMPushListener- (void)onNotificationClicked:(NSString *)ext {// Getting ext for Definition redirect}
You need to implement the
- 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;}
1. Integration of TIMPush
This plugin is available on pub.dev under the package name:
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
2. Registration for push notifications (after successful registration, you can receive online push notifications)
You can define a function to receive this callback and use it to navigate to the corresponding Session Page or your Business Page.
Example below:
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");
Note:
1. After successfully registering for offline push service, you can obtain the unique push ID, RegistrationID, through the getRegistrationID interface. Then, you can push messages to the specified device based on the RegistrationID.
2. RegistrationID is the unique push ID of the device. It is automatically generated after successfully registering for push service by default, but it also supports user-defined settings. It allows users to push messages to the specified device based on the RegistrationID. Reinstalling the app will change it, so it needs to be called before registering for push service.
String registrationID = ""; //Push ID, needs to be called before registering for push serviceTencentCloudChatPush().setRegistrationID(registrationID: registrationID);
3. Implement click notification bar callback
The Application class inherits from TencentCloudChatPushApplication
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();}}
Note:
If you have already created your own Application for other purposes, directly
extend TencentCloudChatPushApplication
and ensure that the onCreate()
function calls super.onCreate();
.The AppDelegate class inherits from TIMPushDelegate
import UIKit
import Flutter
// Add these two import lines
import TIMPush
import 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
func
offlinePushCertificateID
(
)
->
Int32
{
return
TencentCloudChatPushFlutterModal
.
shared
.
offlinePushCertificateID
(
)
;
}
// Add this function
func
applicationGroupID
(
)
->
String
{
return
TencentCloudChatPushFlutterModal
.
shared
.
applicationGroupID
(
)
}
// Add this function
func
onRemoteNotificationReceived
(
_ notice
:
String
?
)
->
Bool
{
TencentCloudChatPushPlugin
.
shared
.
tryNotifyDartOnNotificationClickEvent
(
notice
)
return
true
}
}
1. HBuilderX 4.29 has a bug, please use HBuilderX 4.36 or a higher version, and upgrade the uni-app Tencent Cloud Push Service (Push) to version 1.1.0 or higher.
2. Import the uni-app Tencent Cloud Push Service (Push) plugin into the project in HbuilderX. As shown in the figure:
3. Import and register Tencent Cloud Push Service (Push) in App.vue (after successful registration, you can receive online push notifications)
Note:
After successfully registering for push service with
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);});
4. Use cloud certificate to generate custom base
Click HBuilderX's Run > Run on Phone or Emulator > Create Custom Debug Base, and use the cloud certificate to create an Android or iOS custom debug base. As shown in the figure:
1. Create a React Native project (skip this step if you already have a project)
npx @react-native-community/cli@latest init MyReactNativeApp --version 0.75.0
2. Integrate @tencentcloud/react-native-push
npm install @tencentcloud/react-native-push --save
3. Register for push notifications
Copy the following code to
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);});}
4. Configure Native Modules and dependencies
1. Open the
MyReactNativeApp/android
directory using Android Studio.2. Modify the project entry file.
...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;}...}
3. After completing the above steps, select
File > Sync Project with Gradle Files
.1. Open
MyReactNativeApp/ios/MyReactNativeApp.xcworkspace
using XCode.2. Go to the
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
3. Enable push notification feature in the app. Open the Xcode project, and on the Project > Target > Capabilities page, select and add Push Notifications.
5. Run on a real device (make sure to enable phone notification permissions and allow app notifications before testing.)
From the root directory of the project, run the following command in the command prompt to install and launch your application on the device:
npm run android
npm run ios
Step 3: Specify RegistrationID for push
Note:
1. For official use, please refer to the following methods.
Send to all users or tagged users, for details, see Pushing to All Users/Tag Push.
Batch send to specified RegistrationID, for details, see Single Push.
2. For details on the offline channel, see manufacturer channel configuration.