bindPushKitToken method
~english Binds the Apple PushKit token, which is used for VoIP push notifications.
This method is available on iOS only; on other platforms it does nothing.
Param deviceToken The PushKit token reported by PKPushRegistry, in hexadecimal.
The PushKit certificate name must be set with ChatOptions.pushKitCertName when the SDK is initialized, because the certificate name cannot be changed at runtime.
The native SDK caches the token before binding it: if the current user is not logged in
yet, this call fails with ChatError, but the token stays cached and is bound
automatically after the next successful login. ChatClient.logout with
unbindDeviceToken: true unbinds the PushKit token as well.
Throws A description of the issue that caused this exception. See ChatError
~end
~chinese 绑定苹果 PushKit token,用于 VoIP 推送。
仅 iOS 平台有效,其他平台调用不做任何处理。
Param deviceToken PKPushRegistry 回调返回的 PushKit token,十六进制字符串。
PushKit 证书名称需要在 SDK 初始化时通过 ChatOptions.pushKitCertName 设置, 因为证书名称不支持运行时修改。
原生 SDK 会先缓存 token 再执行绑定:若此时当前用户尚未登录,本次调用会抛出 ChatError,
但 token 已缓存,下次登录成功后 SDK 会自动完成绑定。调用 ChatClient.logout 且
unbindDeviceToken 为 true 时,会同时解绑 PushKit token。
Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError。
~end
Implementation
Future<void> bindPushKitToken({required String deviceToken}) async {
if (Platform.isIOS) {
try {
Map req = {'deviceToken': deviceToken};
Map result = await platform_interface.Client.instance.pushManager
.callNativeMethod(ChatMethodKeys.bindPushKitToken, req);
ChatError.hasErrorFromResult(result);
} catch (e) {
rethrow;
}
} else {
return;
}
}