【iOS】 DeviceToken 解析 (支持iOS13)

OC:

if (![deviceToken isKindOfClass:[NSData class]]) return;
NSMutableString *valueString = [NSMutableString string];
const unsigned *tokenBytes = [deviceToken bytes];
NSInteger count = deviceToken.length;
for (int i = 0; i < count; i++) {
    [valueString appendFormat:@"%02x", tokenBytes[i]&0x000000FF];
}

Swift :

let token = deviceToken.reduce("", {$0 + String(format: "%02x", $1)})

总结起来其实就是把Data类型转化为hex类型的字符串

你可能感兴趣的:(【iOS】 DeviceToken 解析 (支持iOS13))