使用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:"")