加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift3.0获取友盟device_token

发布时间:2020-12-14 06:17:07 所属栏目:百科 来源:网络整理
导读:使用swift3.0集成友盟推送卡在获取device_token这一步上了 //正常OC代码这样获取 在 didRegisterForRemoteNotificationsWithDeviceToken 中添加如下语句 NSLog (@ "%@" ,[[[[deviceToken description] stringByReplacingOccurrencesOfString: @ "" withStrin

使用swift3.0集成友盟推送卡在获取device_token这一步上了

//正常OC代码这样获取
在 didRegisterForRemoteNotificationsWithDeviceToken 中添加如下语句

NSLog(@"%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
                  stringByReplacingOccurrencesOfString: @">" withString: @""]
                 stringByReplacingOccurrencesOfString: @" " withString: @""]);

而转成swift3.0,一开始我是这么写的

let token: String = deviceToken.description.replacingOccurrences(of: "<",with: "").replacingOccurrences(of: ">",with: "").replacingOccurrences(of: " ",with: "")

//结果打印出来的值都是32bytes

网上找了好久才找到一个答案,感谢博主
swift3升级后获取deviceToken打印为32bytes处理

//将Data转化为NSData就行了
let device = NSData(data: deviceToken)
let deviceId = device.description.replacingOccurrences(of:"<",with:"").replacingOccurrences(of:">",with:"").replacingOccurrences(of:" ",with:"")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读