You should not rely on the NSData description method (which is actually the NSObject description method) to provide the same results from each version of iOS to the next. Apple may change what this description displays.
The device token is actually HEX in NSData format. You need to convert NSData. You can use something like the following:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[NSUserDefaults standardUserDefaults] setObject:[deviceToken stringWithHexBytes] forKey:@"DeviceToken"]; }
The stringWithHexBytes method is a category in NSData as follows:
NSData + Hex.h
@interface NSData (Hex) - (NSString *) stringWithHexBytes; @end
NSData + Hex.m
#import "NSData+Hex.h" @implementation NSData (Hex) - (NSString*) stringWithHexBytes { NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:([self length] * 2)]; const unsigned char *dataBuffer = [self bytes]; for (int i = 0; i < [self length]; ++i) { [stringBuffer appendFormat:@"%02X", (unsigned long)dataBuffer[ i ]]; } return [[stringBuffer retain] autorelease]; } @end
source share