Device type | Custom redirect supported |
iOS | Supported |
FCM | Supported |

{"MsgBody": [...] // Same as the MsgBody description"OfflinePushInfo": {"PushFlag": 0,"Title":"Offline push title","Desc": "Offline push content","Ext": "{\\"entity\\":{\\"key1\\":\\"value1\\",\\"key2\\":\\"value2\\"}}" // Passthrough field; use a JSON string for push}}
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setTitle("Push title");v2TIMOfflinePushInfo.setDesc("Push content");OfflinePushExtInfo offlinePushExtInfo = new OfflinePushExtInfo();offlinePushExtInfo.getBusinessInfo().setSenderId("senderID");offlinePushExtInfo.getBusinessInfo().setSenderNickName("senderNickName");if (chatInfo.getType() == V2TIMConversation.V2TIM_GROUP) {offlinePushExtInfo.getBusinessInfo().setChatType(V2TIMConversation.V2TIM_GROUP);offlinePushExtInfo.getBusinessInfo().setSenderId("groupID");}// Fill passthrough fieldv2TIMOfflinePushInfo.setExt(new Gson().toJson(offlinePushExtInfo).getBytes());final V2TIMMessage v2TIMMessage = message.getTimMessage();String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {TUIChatLog.v(TAG, "sendMessage onSuccess:" + v2TIMMessage.getMsgID());message.setMsgTime(v2TIMMessage.getTimestamp());TUIChatUtils.callbackOnSuccess(callBack, message);}});

TIMPushManager.getInstance().addPushListener(new TIMPushListener() {@Overridepublic void onNotificationClicked(String ext) {Log.d(TAG, "onNotificationClicked =" + ext);// Get ext for custom redirect// Example: navigate to the corresponding chat pageOfflinePushExtInfo offlinePushExtInfo = null;try {offlinePushExtInfo = new Gson().fromJson(extString, OfflinePushExtInfo.class);if (offlinePushExtInfo.getBusinessInfo().getChatAction() == OfflinePushExtInfo.REDIRECT_ACTION_CHAT) {String senderId = offlinePushExtInfo.getBusinessInfo().getSenderId();if (TextUtils.isEmpty(senderId)) {return;}TUIUtils.startChat(senderId, offlinePushExtInfo.getBusinessInfo().getSenderNickName(), offlinePushExtInfo.getBusinessInfo().getChatType());}} catch (Exception e) {Log.e(TAG, "getOfflinePushExtInfo e: " + e);}}});
TUICore.registerEvent(TUIConstants.TIMPush.EVENT_NOTIFY, TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION, new ITUINotification() {@Overridepublic void onNotifyEvent(String key, String subKey, Map<String, Object> param) {Log.d(TAG, "onNotifyEvent key = " + key + "subKey = " + subKey);if (TUIConstants.TIMPush.EVENT_NOTIFY.equals(key)) {if (TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION.equals(subKey)) {if (param != null) {String extString = (String)param.get(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);// Get ext for custom redirect}}}}});
// Dynamically register the broadcastIntentFilter 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);// Get ext for custom redirect} else {Log.e(TAG, "onReceive ext is null");}}}
{"MsgBody": [...] // Same as the MsgBody description"OfflinePushInfo": {"PushFlag": 0,"Title":"Offline push title","Desc": "Offline push content","Ext": "{\\"entity\\":{\\"key1\\":\\"value1\\",\\"key2\\":\\"value2\\"}}" // Passthrough field; use a JSON string for push}}
#import <TUICore/OfflinePushExtInfo.h>V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"Push title";pushInfo.desc = @"Push content";BOOL isGroup = groupID.length > 0;NSString *senderId = isGroup ? (groupID) : ([TUILogin getUserID]);NSString *nickName = isGroup ? (conversationData.title) : ([TUILogin getNickName] ?: [TUILogin getUserID]);OfflinePushExtInfo *extInfo = [[OfflinePushExtInfo alloc] init];OfflinePushExtBusinessInfo * entity = extInfo.entity;entity.action = 1;entity.content = @"Push content";entity.sender = senderId;entity.nickname = nickName;entity.faceUrl = [TUILogin getFaceUrl] ?: @"";entity.chatType = [isGroup ? @(V2TIM_GROUP) : @(V2TIM_C2C) integerValue];entity.version = kOfflinePushVersion;// Passthrough fieldpushInfo.ext = [extInfo toReportExtString];

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[TIMPushManager addPushListener:self];return YES;}#pragma mark - TIMPushListener- (void)onNotificationClicked:(NSString *)ext {// Get ext for custom redirect}
- onRemoteNotificationReceived method in AppDelegate.m.#pragma mark - TIMPush- (BOOL)onRemoteNotificationReceived:(NSString *)notice {//- If you return YES, TIMPush will not run the built-in TUIKit offline push parsing logic and you handle everything yourself;//NSString *ext = notice;//OfflinePushExtInfo *info = [OfflinePushExtInfo createWithExtString:ext];//return YES;//- If you return NO, TIMPush continues the built-in TUIKit offline push parsing logic and still callbacks - navigateToBuiltInChatViewController:groupID:.return NO;}

TIMPushListener timPushListener = TIMPushListener(onNotificationClicked: (String ext) {debugPrint("ext: $ext");// Get ext for custom redirect});tencentCloudChatPush.addPushListener(listener: timPushListener);
{required String ext, String? userID, String? groupID}.void _onNotificationClicked({required String ext, String? userID, String? groupID}) {print("_onNotificationClicked: $ext, userID: $userID, groupID: $groupID");if (userID != null || groupID != null) {// Redirect to the corresponding Message page based on userID or groupID.} else {// Write your own parsing for the ext field and redirect to the target page.}}
TencentCloudChatPush().registerPush succeeds, you can receive offline push notifications.TencentCloudChatPush().registerPush(onNotificationClicked: _onNotificationClicked,sdkAppId: yourSdkAppId,appKey: "AppKey",apnsCertificateID: yourCertificateID);

onShow callback of App.vue, when the device receives an offline push and launches the app, the business can get the push extension information through getNotificationExtInfo.export default {onLaunch: function() {},onShow: function() {console.log('App Show')Push.getNotificationExtInfo((extInfo) => {console.log('getNotificationExtInfo ok', extInfo);// Perform custom redirect here.})},onHide: function() {console.log('App Hide')}}

import Push from '@tencentcloud/react-native-push';if (Push) {// 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);});}

const listener = (param) => {console.log('onEvent', JSON.stringify(param));}App({onLaunch: function () {console.log('App Show')Push.addPushListener(Push.EventName.NOTIFICATION_CLICKED, listener);}
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan