bindDeviceToken method
~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. This parameter is required on
Android and is ignored on iOS:
- 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: not used. Set the APNs certificate name with ChatOptions.apnsCertName when the SDK is initialized, because the certificate name cannot be changed at runtime.
Throws A description of the issue that caused this exception. See ChatError
~end
~chinese 绑定设备的推送 token。
Param deviceToken 平台推送服务返回的推送 token。
Param notifierName 平台的推送凭据。Android 必填,iOS 忽略:
- Android:厂商推送凭据,例如 FCM 的 Sender ID、华为/荣耀的 App ID、小米/魅族的 App ID、
OPPO 的 App Key、vivo 的
appId#appKey。不能为空,否则原生 SDK 返回参数非法错误; - iOS:不使用该参数。APNs 证书名称请在 SDK 初始化时通过 ChatOptions.apnsCertName 设置, 因为证书名称不支持运行时修改。
Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError。
~end
Implementation
Future<void> bindDeviceToken(
{required String deviceToken, String? notifierName}) async {
try {
Map req = {
// Keep the key on every platform: iOS ignores it, and Android reports the native
// invalid-parameter error instead of a missing-key error when it is empty.
'notifierName': notifierName ?? '',
'deviceToken': deviceToken,
};
Map result = await platform_interface.Client.instance.pushManager
.callNativeMethod(ChatMethodKeys.bindDeviceToken, req);
ChatError.hasErrorFromResult(result);
} catch (e) {
rethrow;
}
}