ios--apns Device token的获得和改变详解
2015-10-13 15:27
751 查看
Device token for an iPhone device生成之后就永远不变吗?
不是,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有可能改变,所以建议在app start时(即在didFinishLaunchingWithOptions
里)调用registerForRemoteNotificationTypes来获取device
token以检查device token是否改变,如果改变了就应该把新token传给push provider。(官方描述:An application should register every time it launches and give its provider the current token)
device token应该存储在NSUserDefaults来达到新旧比较的目的
那么旧device token在push provider对应的record怎么办?
方案1:把旧device token send to provider and request delete record
方案2:使用apns feedback
service。
方案2可能更好些,因为总是需要使用apns feedback service来处理用户在device里删除app的情况。
调用registerForRemoteNotificationTypes方法后,成功注册后,APNS就会返回一个device
token,然后回调delegate methoddidRegisterForRemoteNotificationsWithDeviceToken,
如果注册失败,则回调delegate method didFailToRegisterForRemoteNotificationsWithError。
注意:
* 在第一次调用registerForRemoteNotificationTypes方法时没有联网,则既不会调用didRegisterForRemoteNotificationsWithDeviceToken,也不会调用didFailToRegisterForRemoteNotificationsWithError
*在第一次调用registerForRemoteNotificationTypes注册成功后,之后即使没有联网,再调用registerForRemoteNotificationTypes时都会以最上一次的device
token作为参数回调didRegisterForRemoteNotificationsWithDeviceToken方法。
* (官方描述) If
your application has previously registered, calling
operating system passing the device token to the delegate immediately without incurring additional overhead.
from:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2
不是,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有可能改变,所以建议在app start时(即在didFinishLaunchingWithOptions
里)调用registerForRemoteNotificationTypes来获取device
token以检查device token是否改变,如果改变了就应该把新token传给push provider。(官方描述:An application should register every time it launches and give its provider the current token)
device token应该存储在NSUserDefaults来达到新旧比较的目的
那么旧device token在push provider对应的record怎么办?
方案1:把旧device token send to provider and request delete record
方案2:使用apns feedback
service。
方案2可能更好些,因为总是需要使用apns feedback service来处理用户在device里删除app的情况。
调用registerForRemoteNotificationTypes方法后,成功注册后,APNS就会返回一个device
token,然后回调delegate methoddidRegisterForRemoteNotificationsWithDeviceToken,
如果注册失败,则回调delegate method didFailToRegisterForRemoteNotificationsWithError。
注意:
* 在第一次调用registerForRemoteNotificationTypes方法时没有联网,则既不会调用didRegisterForRemoteNotificationsWithDeviceToken,也不会调用didFailToRegisterForRemoteNotificationsWithError
*在第一次调用registerForRemoteNotificationTypes注册成功后,之后即使没有联网,再调用registerForRemoteNotificationTypes时都会以最上一次的device
token作为参数回调didRegisterForRemoteNotificationsWithDeviceToken方法。
* (官方描述) If
your application has previously registered, calling
registerForRemoteNotificationTypes:results in the
operating system passing the device token to the delegate immediately without incurring additional overhead.
from:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2
相关文章推荐
- IOS 开发过程中的 消息通知 小红点
- iOS--xib界面与和代码相关联
- iOS开发过程中的各种坑
- 2015年最新苹果开发者账号注册流程详解
- PhoneGap/Cordova插件开发入门(IOS版)(一)
- ios推送 程序未启动,收到推送消息,打开应用后跳转到相应的活动页面的代码。
- iOS 按钮小知识点总结
- 在ios中开发使用自动布局约束小注意点。
- IOS远程推送(转载)
- iOS ViewController生命周期
- NSPredicate 模糊、精确、查询
- iOS中的动画
- iOS 9 适配
- IOS 在功能 autorelease release
- 在iOS开发中如何裁剪一个圆图像
- iOS英语—》中国本土化,如调用专辑,摄像头的变化“cancel”,“photos”至“撤消”,“摄像头”
- iOS 多线程开发
- 用segmentedControl控制显示n个页面之一(思想、思路、无代码)--iOS开发
- IOS中简单的KVO概念理解与应用
- iOS开发-- 开发环境,证书和授权文件