bindDeviceToken method

Future<void> bindDeviceToken({
  1. required String notifierName,
  2. required String deviceToken,
})

~english Binds the push token of the device.

Param deviceToken The push token reported by the push service of the platform.

Param notifierName The push credential of the platform:

  • Android: the vendor push credential, for example the FCM Sender ID, the HUAWEI/Honor app ID, the Xiaomi/Meizu app ID, the OPPO app key, or the vivo appId#appKey. It must not be empty, otherwise the native SDK returns an invalid-parameter error;
  • iOS: the APNs certificate name. It is optional here and takes precedence over ChatOptions.apnsCertName when it is not empty, so both the initialization option and this argument can be used to set the certificate name.

Throws A description of the issue that caused this exception. See ChatError ~end

~chinese 绑定设备的推送 token。

Param deviceToken 平台推送服务返回的推送 token。

Param notifierName 平台的推送凭据:

  • Android:厂商推送凭据,例如 FCM 的 Sender ID、华为/荣耀的 App ID、小米/魅族的 App ID、 OPPO 的 App Key、vivo 的 appId#appKey。不能为空,否则原生 SDK 返回参数非法错误;
  • iOS:APNs 证书名称。此处为非必填,非空时优先级高于 ChatOptions.apnsCertName, 因此初始化配置与本参数两种方式都可用。

Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError。 ~end

Implementation

Future<void> bindDeviceToken(
    {required String notifierName, required String deviceToken}) async {
  try {
    Map req = {'notifierName': notifierName, 'deviceToken': deviceToken};
    Map result = await platform_interface.Client.instance.pushManager
        .callNativeMethod(ChatMethodKeys.bindDeviceToken, req);
    ChatError.hasErrorFromResult(result);
  } catch (e) {
    rethrow;
  }
}