移动推送: deviceId、deviceToken的概念和区别是什么?
deviceId
- deviceId是推送系统中设备的唯一标识,是长度为32位的数字和小写字母的组合;
- 在控制台或通过OpenAPI推送时,可以指定终端推送,即通过指定终端的deviceId推送;
- 请在SDK初始化完成后,通过如下方式获取deviceId。
Android获取deviceId
- [backcolor=transparent]CloudPushService[backcolor=transparent] pushService [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]PushServiceFactory[backcolor=transparent].[backcolor=transparent]getCloudPushService[backcolor=transparent]();
- [backcolor=transparent]String[backcolor=transparent] deviceId [backcolor=transparent]=[backcolor=transparent] pushService[backcolor=transparent].[backcolor=transparent]getDeviceId[backcolor=transparent]();
iOS获取deviceId
- [backcolor=transparent]NSString[backcolor=transparent] deviceId [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]CloudPushSDK[backcolor=transparent] getDeviceId[backcolor=transparent]];
deviceToken
- deviceToken为iOS设备向APNs注册推送通知服务时,返回的设备标识符,请不要同deviceId混淆。
- 获取到deviceToken后,可调用registerDevice接口上报deviceToken到推送服务器,在上报成功回调中可获取到转换后的deviceToken,如下:
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]application[backcolor=transparent]:([backcolor=transparent]UIApplication[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]application didRegisterForRemoteNotificationsWithDeviceToken[backcolor=transparent]:([backcolor=transparent]NSData[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]deviceToken [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]CloudPushSDK[backcolor=transparent] registerDevice[backcolor=transparent]:[backcolor=transparent]deviceToken withCallback[backcolor=transparent]:^([backcolor=transparent]CloudPushCallbackResult[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]res[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]res[backcolor=transparent].[backcolor=transparent]success[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"Register deviceToken success, deviceToken: %@"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]CloudPushSDK[backcolor=transparent] getApnsDeviceToken[backcolor=transparent]]);
- [backcolor=transparent] [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]else[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"Register deviceToken failed, error: %@"[backcolor=transparent],[backcolor=transparent] res[backcolor=transparent].[backcolor=transparent]error[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]}];
- [backcolor=transparent]}
收起
猫饭先生
2017-10-23 11:25:30
3982
0
0
条回答
写回答
取消
提交回答