在iOS 13的系统版本中,token的格式发生了变得,导致不能按照iOS13之前的处理方法去处理然后再上传服务器。
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
DBLOG_FUN;
NSString *_deviceToken = @"";
if (@available(iOS 13.0, *)) {
if (![deviceToken isKindOfClass:[NSData class]]) return;
const unsigned *tokenBytes = [deviceToken bytes];
_deviceToken = [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])];
[[DataStore sharedStore] setDeviceToken:_deviceToken];
DBLOG(@"_deviceToken:%@", _deviceToken);
}else if([deviceToken.description length] > 0) {
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"<>"];
_deviceToken = [deviceToken.description stringByTrimmingCharactersInSet:set];
_deviceToken = [_deviceToken stringByReplacingOccurrencesOfString:@" " withString:@""];
[[DataStore sharedStore] setDeviceToken:_deviceToken];
DBLOG(@"_deviceToken:%@", _deviceToken);
}
}
网友评论