iOSDevicetoken的问题-创新互联

Device token for an iPhone device生成之后就永远不变吗?

成都创新互联公司是一家专注于成都网站设计、网站建设与策划设计,富顺网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:富顺等地区。富顺做网站价格咨询:18980820575

不是,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.

上述东东参考官方网站关于Registering for Remote Notifications的讲解

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻标题:iOSDevicetoken的问题-创新互联
本文URL:http://myzitong.com/article/dhgjed.html