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);
}
上一篇:沈师PTA--JAVA程序设计-第4章习题集(2)--判断题答案版


下一篇:RunLoop