iOS APNS device Token 是否会改变?
2015-09-21 10:20
519 查看
通过真机调试以下代码:[b]开发环境获取的deviceToken和发布环境获取的deviceToken当然是不一样的![/b]
而且在开发环境和发布环境中如果开发证书不一样的话获取的deviceToken也不一样,亲测!!!
[b]文章末尾讨论发布环境的deviceToken 。。。 [/b]
现在来讨论发布环境的deviceToken,之前我认为是不会改变的,但后来发现貌似会变。当然这个调试就需要去回复iPhone手机了,如果你愿意可以去试试,弄个不用的iPhone4,iPhone4s之类的。
if a device is wiped, it will get a new device token. (如果一个设备被清除,它将获得一个新的设备令牌。)
官方网站是这样写的: If
the user restores backup data to a new device or computer, or reinstalls the operating system, the device token changes
正是因为device有可能改变,所以官方描述:An
application should register every time it launches and give its provider the current token
所以...不要判断APP里是否已经保存的deviceToken 就不去register了,
should every time !!
另见 iOS
Push Notification注意事项
而且在开发环境和发布环境中如果开发证书不一样的话获取的deviceToken也不一样,亲测!!!
[b]文章末尾讨论发布环境的deviceToken 。。。 [/b]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] init]; self.window.backgroundColor = [UIColor whiteColor]; self.window.frame = [[UIScreen mainScreen] bounds]; [self registerNotification:application]; [self.window makeKeyAndVisible]; return YES; }
- (void)registerNotification:(UIApplication *)application { if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8) { if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; } }else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; NSLog(@"not isIOS8"); } }
///Token值成功获取的时候走的是这个方法(Token值不能带空格) -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"deviceToken----------->%@",deviceToken); NSString *pushToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""] ; NSLog(@"pushToken----------->%@",pushToken); } ///Token值获取失败的时候走的是这个方法 -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Token值获取失败,error--->%@",error); } ///应用程序处在打开状态,且服务器有推送消息过来时,以及通过推送打开应用程序,走的是这个方法 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { for (id key in userInfo) { NSLog(@"%@:%@",key, [userInfo objectForKey:key]); } ///Icon推送数量设为0 application.applicationIconBadgeNumber=0; }
现在来讨论发布环境的deviceToken,之前我认为是不会改变的,但后来发现貌似会变。当然这个调试就需要去回复iPhone手机了,如果你愿意可以去试试,弄个不用的iPhone4,iPhone4s之类的。
if a device is wiped, it will get a new device token. (如果一个设备被清除,它将获得一个新的设备令牌。)
官方网站是这样写的: If
the user restores backup data to a new device or computer, or reinstalls the operating system, the device token changes
正是因为device有可能改变,所以官方描述:An
application should register every time it launches and give its provider the current token
所以...不要判断APP里是否已经保存的deviceToken 就不去register了,
should every time !!
另见 iOS
Push Notification注意事项
相关文章推荐
- XCODE6+ios8真机调试[转]
- 七牛云存储xcode更新为ios9使用七牛的ios sdk上传报错
- iOS开发-zbar解析中文乱码情况
- iOS:转载FMDB文档
- iOS 小标签
- iOS stretchableImageWithLeftCapWidth 图片放大不变形
- iOS开发 xib错误 One" nib but the view outlet was not set
- iOS 百度地图SDK使用
- iOS开发脚踏实地学习day11-导航控制器
- IOS工具篇
- IOS汇总
- IOS开发测试之单元测试一
- iOS 技术分享5
- iOS之旅--使用控件的属性frame、center、bounds
- iOS开发中的几个手势操作实例分享
- Masonry介绍与使用实践:快速上手Autolayout
- IOS9.0中hash值的bug与解决方案
- iOS 不要使用tag传递TableViewCell的indexPath值
- Nagios检测工具介绍
- iOS 汉字转拼音