iOS 远程推送将deviceToken转换成字符串

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容