iOS推送deviceToken问题

不标准的写法,在iOS13上,再也不能获取到正确的deviceToken

NSString *deviceTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""]stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *dt = [deviceToken description];
dt = [dt stringByReplacingOccurrencesOfString: @"<" withString: @""];
dt = [dt stringByReplacingOccurrencesOfString: @">" withString: @""];
dt = [dt stringByReplacingOccurrencesOfString: @" " withString: @""];

正确的写法

NSMutableString *deviceTokenString = [NSMutableString string];    
const char *bytes = deviceToken.bytes;
NSInteger iCount = deviceToken.length;
for (NSInteger i = 0; i < iCount; i++) {
    [deviceTokenString appendFormat:@"%02x", bytes[i]&0x000000FF];
}
NSLog(@"deviceTokenString:%@",deviceTokenString);

你可能感兴趣的:(iOS推送deviceToken问题)