我希望“tokenData”等于“token”中的“deviceToken”

时间:2012-10-13 11:27:46

标签: iphone nsstring nsdata

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{
    NSLog(@"%@", [NSString stringWithFormat:@"%@", deviceToken]); 

    //display: 
    //<682e6887 ad7c7268 38861e90 6f4b9ba7 ced1299e abf3084b ca2ca75a 11111111>


    NSString *token = @"<682e6887 ad7c7268 38861e90 6f4b9ba7 ced1299e abf3084b ca2ca75a 11111111>";
    NSData *tokenData = [token dataUsingEncoding:NSASCIIStringEncoding];
    NSLog(@"%@", [NSString stringWithFormat:@"%@", tokenData]); 

    //display:
    //3c36383265363838372061643763373236382033383836316539302036663462396261372063656431323939652061626633303834622063613263613735612031313131313131313e
}

1 个答案:

答案 0 :(得分:0)

我无法理解你在说什么。但您错误地使用了NSDataNSString

NSString *token=[[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding];

NSData *deviceToken = [token dataUsingEncoding:NSUTF8StringEncoding];

使用以上两个功能将NSString转换为NSData,反之亦然。