registerOnNotificationClickedEvent method

  1. @override
Future<TencentCloudChatPushResult> registerOnNotificationClickedEvent({
  1. required dynamic onNotificationClicked({
    1. required String ext,
    2. String? groupID,
    3. String? userID,
    }),
})
override

Implementation

@override
Future<TencentCloudChatPushResult> registerOnNotificationClickedEvent({
  required Function({required String ext, String? userID, String? groupID}) onNotificationClicked,
}) async {
  try {
    _tencentCloudChatPushModal.onNotificationClicked = onNotificationClicked;
    _methodChannel.setMethodCallHandler(_tencentCloudChatPushModal.handleMethod);
    // ohos 上仅绑定 Dart handler,不 invoke native:通知点击派发由 native 的
    // TIMPushListener.onNotificationClicked 通过双通道 invokeMethod 直接触发 modal handler。
    // 这里 handler 绑定确实生效,因此返回 code=0 是正确语义;同时 `TencentCloudChatPush.registerPush`
    // 内部依赖本方法返回 0 才会继续走 registerPush 主流程,改为错误码会破坏 ohos 注册链路。
    if (Platform.isAndroid || Platform.isIOS) {
      await _methodChannel.invokeMethod("registerOnNotificationClickedEvent");
    }
    return TencentCloudChatPushResult(code: 0);
  } on PlatformException catch (e) {
    return TencentCloudChatPushResult(
      code: int.tryParse(e.code) ?? -1,
      errorMessage: e.message,
    );
  }
}