iOS实用知识点

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);
上一篇下一篇

猜你喜欢

热点阅读