tencent cloud

文档反馈

自定义点击跳转

最后更新时间:2024-12-30 17:22:22
    Android
    iOS
    Flutter
    收到离线推送后,通知栏会显示推送信息如图所示,单击通知栏可以自定义打开应用的界面。
    1. 控制台配置点击后续动作按如下配置,选择打开应用内指定界面,插件用户会默认填写跳转参数。
    
    2. 收到推送消息后点击通知栏,组件会回调该点击事件和透传离线消息。
    自定义点击跳转实现
    自定义点击跳转实现(旧方案)
    注意:
    注册回调时机建议放在应用 Application 的 oncreate() 函数中。
    TIMPushManager.getInstance().addPushListener(new TIMPushListener() {
    @Override
    public void onNotificationClicked(String ext) {
    Log.d(TAG, "onNotificationClicked =" + ext);
    // 获取 ext 自定义跳转
    }
    });
    组件会以回调或者广播形式通知应用,应用在回调中配置 App 的跳转页面即可。
    注意:
    注册回调时机建议放在应用 Application 的 oncreate() 函数中。
    1. 回调方式如下:
    TUICore.registerEvent(TUIConstants.TIMPush.EVENT_NOTIFY, TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION, new ITUINotification() {
    @Override
    public 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);
    // 获取 ext 自定义跳转
    }
    }
    }
    }
    });
    2. 广播方式如下:
    // 动态注册广播
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TUIConstants.TIMPush.NOTIFICATION_BROADCAST_ACTION);
    LocalBroadcastManager.getInstance(context).registerReceiver(localReceiver, intentFilter);
    
    //广播接收者
    public class OfflinePushLocalReceiver extends BroadcastReceiver {
    public static final String TAG = OfflinePushLocalReceiver.class.getSimpleName();
    
    @Override
    public 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);
    // 获取 ext 自定义跳转
    
    } else {
    Log.e(TAG, "onReceive ext is null");
    }
    }
    }
    如果您需要自定义解析收到的远程推送,您可按照如下方法实现:
    自定义点击跳转实现
    自定义点击跳转实现(旧方案)
    注意:
    注册回调时机建议放在应用 AppDelegate 的 didFinishLaunchingWithOptions 函数中。
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [TIMPushManager addPushListener:self];
    return YES;
    }
    #pragma mark - TIMPushListener
    - (void)onNotificationClicked:(NSString *)ext {
    // 获取 ext 自定义跳转
    }
    您需要在 AppDelegate.m 文件中实现 - onRemoteNotificationReceived 方法。
    #pragma mark - TIMPush
    - (BOOL)onRemoteNotificationReceived:(NSString *)notice {
    //- 如果返回 YES, TIMPush 将不在执行内置的 TUIKit 离线推送解析逻辑,完全交由您自行处理;
    //NSString *ext = notice;
    //OfflinePushExtInfo *info = [OfflinePushExtInfo createWithExtString:ext];
    //return YES;
    //- 如果返回 NO,TIMPush 将继续执行内置的 TUIKit 离线推送解析逻辑,继续回调 - navigateToBuiltInChatViewController:groupID: 方法。
    return NO;
    }

    步骤1: 厂商配置

    控制台配置点击后续动作按如下配置,选择打开应用内指定界面,插件用户会默认填写跳转参数。
    

    步骤2: 客户端代码配置

    参见 客户端代码配置,完成配置。

    步骤3: 处理消息点击回调, 并解析参数

    如果您需要自定义解析收到的远程推送,您可按照如下方法实现:
    自定义点击跳转实现
    自定义点击跳转实现(旧方案)
    TIMPushListener timPushListener = TIMPushListener(
    onNotificationClicked: (String ext) {
    debugPrint("ext: $ext");
    // 获取 ext 自定义跳转
    }
    );
    tencentCloudChatPush.addPushListener(listener: timPushListener);
    1、请定义一个函数,用于接受推送消息点击回调事件.
    该函数请定义成 {required String ext, String? userID, String? groupID} 的入参形式。
    其中,ext字段,为该消息所携带的完整 ext 信息,由发送方指定,如果未指定,则有默认值。您可根据解析该字段,跳转至对应页面。
    userID 和 groupID 字段,为本插件,自动尝试解析 ext Json String, 获取里面携带的单聊对方 userID 和 群聊 groupID 信息。如果您未自定义 ext 字段,ext 字段由 SDK 或 UIKit 默认指定,则可使用此处的默认解析。如果尝试解析失败,则为 null 空。
    您可定义一个函数来接收该回调,并据此跳转至对应会话页面或您的业务页面。
    示例如下:
    void _onNotificationClicked({required String ext, String? userID, String? groupID}) {
    print("_onNotificationClicked: $ext, userID: $userID, groupID: $groupID");
    if (userID != null || groupID != null) {
    // 根据 userID 或 groupID 跳转至对应 Message 页面.
    } else {
    // 根据 ext 字段, 自己写解析方式, 跳转至对应页面.
    }
    }
    2、请注意,不要在 Flutter 程序入口的 main 方法中调用。
    调用 TencentCloudChatPush().registerPush 方法成功后,就可以收到离线推送通知了。
    TencentCloudChatPush().registerPush(
    onNotificationClicked: _onNotificationClicked,
    sdkAppId: 您的sdkAppId,
    appKey: "客户端密钥"
    apnsCertificateID: 您配置的证书 ID);

    

    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持