Katedral Pillon Katedral Pillon - 1 year ago 62
iOS Question

iOS device token for push notification inside brackets or not

When I do NSLog on my

, the string is printed within brackets as
"<0000 ... 0000>"
. But all the online tutorials show the numbers/string without any brackets
< ... >
. So should I remove the brackets when saving the deviceToken? And yes, they do get save on my server presently with the brackets. And if I am to remove the brackets, what's the code for doing so?

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

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

this is another choice

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

NSLog(@"device token - %@", deviceTokenString);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download