用于推送通知的iOS设备令牌是否在括号内

时间:2014-11-10 05:37:32

标签: ios objective-c push-notification

当我在deviceToken上执行NSLog时,字符串在括号内打印为"<0000 ... 0000>"。但所有在线教程都显示数字/字符串,没有任何括号< ... >。那么在保存deviceToken时我应该删除括号吗?是的,他们现在用括号在我的服务器上保存。如果我要删除括号,这样做的代码是什么?

-(void)application:(UIApplication *)application
 didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString* deviceTokenString =[NSString stringWithFormat:@"%@",deviceToken];    
    NSLog(@"Device token is %@",deviceTokenString);
}

1 个答案:

答案 0 :(得分:2)

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken  {
    NSString * deviceTokenString = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"content---%@", deviceTokenString);
} 

这是另一种选择

NSString * deviceTokenString = [[[[deviceToken description] 
                        stringByReplacingOccurrencesOfString:@"<"withString:@""] 
                       stringByReplacingOccurrencesOfString:@">" withString:@""] 
                      stringByReplacingOccurrencesOfString: @" " withString: @""];


NSLog(@"device token - %@", deviceTokenString);