码迷,mamicode.com
首页 > 移动开发 > 详细

ios13推送DeviceToken

时间:2019-10-24 15:54:51      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:float   str   log   nss   orm   aci   ide   rto   rem   

//获取DeviceToken成功
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
//Xcode11打的包,iOS13获取Token有变化
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) {
if (![deviceToken isKindOfClass:[NSData class]]) {
//记录获取token失败的描述
return;
}
const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
NSString *strToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSLog(@"deviceToken1:%@", strToken);
return;
} else {
NSString *token = [NSString
stringWithFormat:@"%@",deviceToken];
token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];
token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"deviceToken2 is: %@", token);
}
}

ios13推送DeviceToken

标签:float   str   log   nss   orm   aci   ide   rto   rem   

原文地址:https://www.cnblogs.com/hangman/p/11732100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!