开发者社区> 问答> 正文

移动推送: deviceId、deviceToken的概念和区别是什么?



deviceId

  • deviceId是推送系统中设备的唯一标识,是长度为32位的数字和小写字母的组合;
  • 在控制台或通过OpenAPI推送时,可以指定终端推送,即通过指定终端的deviceId推送;
  • 请在SDK初始化完成后,通过如下方式获取deviceId。


Android获取deviceId

  1. [backcolor=transparent]CloudPushService[backcolor=transparent] pushService [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]PushServiceFactory[backcolor=transparent].[backcolor=transparent]getCloudPushService[backcolor=transparent]();
  2. [backcolor=transparent]String[backcolor=transparent] deviceId [backcolor=transparent]=[backcolor=transparent] pushService[backcolor=transparent].[backcolor=transparent]getDeviceId[backcolor=transparent]();


iOS获取deviceId

  1. [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,如下:
  1. [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]{
  2. [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]{
  3. [backcolor=transparent]        [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]res[backcolor=transparent].[backcolor=transparent]success[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  4. [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]]);
  5. [backcolor=transparent]        [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]else[backcolor=transparent] [backcolor=transparent]{
  6. [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]);
  7. [backcolor=transparent]        [backcolor=transparent]}
  8. [backcolor=transparent]    [backcolor=transparent]}];
  9. [backcolor=transparent]}

展开
收起
猫饭先生 2017-10-23 11:25:30 3982 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
基于RocketMQ Connect 构建全新数据流转处理平 立即下载
云服务总线 CSB App Connect 简介 v1.0 直播 立即下载
低代码开发师(初级)实战教程 立即下载