iOS 实战之将 deviceToken 转换成字符串

方式1

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSMutableString *deviceTokenString1 = [NSMutableStringstring];
    const char *bytes = deviceToken.bytes;
    int iCount = deviceToken.length;
    for (int i = 0; i < iCount; i++) {
        [deviceTokenString1 appendFormat:@"%02x", bytes[i]&0x000000FF];
    }
    NSLog(@"方式1:%@", deviceTokenString1);
}

方式2

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{ 
    NSString *deviceTokenString2 = [[[[deviceTokendescription] stringByReplacingOccurrencesOfString:@"<"withString:@""]
                                                                stringByReplacingOccurrencesOfString:@">" withString:@""]
                                                                stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"方式2:%@", deviceTokenString2);
}

你可能感兴趣的:(iOS 实战之将 deviceToken 转换成字符串)