当我在deviceToken
上执行NSLog时,字符串在括号内打印为"<0000 ... 0000>"
。但所有在线教程都显示数字/字符串,没有任何括号< ... >
。那么在保存deviceToken时我应该删除括号吗?是的,他们现在用括号在我的服务器上保存。如果我要删除括号,这样做的代码是什么?
-(void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString* deviceTokenString =[NSString stringWithFormat:@"%@",deviceToken];
NSLog(@"Device token is %@",deviceTokenString);
}
答案 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);