swift3.0获取友盟device_token

前端之家收集整理的这篇文章主要介绍了swift3.0获取友盟device_token前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用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:"")
原文链接:https://www.f2er.com/swift/321693.html

猜你在找的Swift相关文章