API
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
方式一
NSMutableString *tokenStr = [NSMutableString string];
const char *bytes = deviceToken.bytes;
NSInteger length = deviceToken.length;
for (int i = 0; i < length; i++) {
[tokenStr appendFormat:@"%02x", bytes[i]&0x000000FF];
}
方式二
NSString tokenStr =[[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
或
NSString *description = [deviceToken description];
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"<> "];
NSArray *arr = [description componentsSeparatedByCharactersInSet:set];
NSString *tokenStr = [arr componentsJoinedByString:@""];
结尾
目前各大推送服务提供商基本早已弃用deviceToken