2013-09-26 31 views
3

设备标记第一次可能为空吗?我已经从 设备令牌中删除了空白区,但它仍然会在数据库中显示为空。关于设备标记

deviceTokenStr =[[[[deviceToken description] 
         stringByReplacingOccurrencesOfString: @"<" withString: @""] 
         stringByReplacingOccurrencesOfString: @">" withString: @""] 
         stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    NSLog(@"device token------------%@",deviceTokenStr); 
devicetk=[deviceTokenStr retain]; 
NSLog(@"My token is: %@", deviceTokenStr); 
+0

除调试外,不要使用'description'方法。 Apple不保证它保持不变。使用:'[[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding]]' – zaph

+0

获取'deviceToken'的代码在哪里?试试NSLog(@“deviceToken:%@”,deviceToken);看见了。 – zaph

+0

设备标记在第一次为空。这意味着你想说它会从第二次返回值? –

回答

0

不,它不可能设备标记将返回空值。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken 
{ 
NSString *devicetoken = [[[[devToken description] 
       stringByReplacingOccurrencesOfString:@"<"withString:@""] 
       stringByReplacingOccurrencesOfString:@">" withString:@""] 
       stringByReplacingOccurrencesOfString: @" " withString: @""]; 


NSLog(@"token :: %@", devicetoken); 
}