level 1
swift直接连APNs,获取deviceToken以后,解析方式在IOS13发生了变化。紧急求助。。
2019年12月06日 04点12分
1
level 1
if Int(currentVersion)! >= 13 {
if !(deviceToken is Data) {
//记录获取token失败的描述
return
}
let bytes = [UInt8](deviceToken)
for item in bytes {
deviceTokenStr += String(format:"%02x", item&0x000000FF)
}
} else {
deviceTokenStr = nsdataStr.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
}
解决了,两行代码
2019年12月06日 07点12分
3
level 1
swift ios13以上版本直连APNs获取deviceToken
//currentVersion : 系统的IOS大版本,13以上走新方法,13以下走老方法。
if Int(currentVersion)! >= 13 {
if !(deviceToken is Data) {
//记录获取token失败的描述
return
}
let bytes = [UInt8](deviceToken)
for item in bytes {
deviceTokenStr += String(format:"%02x", item&0x000000FF)
}
} else {
let nsdataStr = NSData.init(data: deviceToken)
deviceTokenStr = nsdataStr.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
}
2019年12月06日 07点12分
4