在 iOS 13 的手机上,NSData类型的 deviceToken 转换成的字符串变成了:
{length = 32, bytes = 0xd7f9fe34 69be14d1 fa51be22 329ac80d ... 5ad13017 b8ad0736 }
用户反映推送失败,网上百度了下,才知道原来的获取方法已经过时。于是修改为:
if (![deviceToken isKindOfClass:[NSData class]]) {
return;
}
const unsigned *tokenBytes = [deviceToken bytes];
NSString *token = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
[[GeneralShareInstance shareInstance] saveToken:token];
NSString *usrId = [[GeneralShareInstance shareInstance] getUsrId];
[self aliasToken:token usrId:usrId];
这样Token就适配好了