iOS推送deviceToken问题
2020-07-23 本文已影响0人
顺手给我new一个对象
不标准的写法,在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);