iOS: Device token and registerForRemoteNotificationTypes, didReceiveRemoteNotification

news/2024/7/8 5:16:03
  分类: Mobile iOS   244人阅读  评论(0)  收藏  举报

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 registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead.

 

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

 

转载于:https://www.cnblogs.com/jiangshiyong/archive/2012/11/19/2547349.html


http://www.niftyadmin.cn/n/3855202.html

相关文章

Java纯POJO类反射到Redis,反射到MySQL

这个是类定义&#xff0c;都是POJO类&#xff0c;纯数据 以下代码将POJO类反射到REDIS中&#xff0c;采用JSON序列化类数据。 public static <T> T save(T model, String indexName) throws Exception {String modelName model.getClass().getSimpleName();Jedis jedis …

PowerDesigner建模工具

PowerDesignerPowerDesigner建模工具 PowerDesigner是Sybase公司的CASE工具集&#xff0c;使用它可以方便地对管理信息系统进行分析设计&#xff0c;它几乎包括了数据库模型设计的全过程。 利用PowerDesigner可以制作数据流程图、概念数据模型、物理数据模型&#xff0c;可以生…

管理时间是空话,集中精力吃青蛙

别再想着管理时间了。找出你一天、一周、一个月、一年、一生中最重要的三件事&#xff0c;它们就是你必须吃掉的“三只青蛙”。 利用帕累托定律&#xff0c;每天划出20%的时间&#xff0c;集中精力&#xff0c;专门对付这三只青蛙。 坚持不懈&#xff0c;你的人生就能取得完全不…

VirtualBox修改UUID实现VM复制

virtualbox是一个很好用的虚拟机软件&#xff0c;可以和VmWare想媲美。缺点也有&#xff0c;就是对CPU虚拟的功能不强。 我用VirtualBox做了一个Ubuntu Server虚拟镜像。我想实现复制几个&#xff0c;然后可以同时装载几个虚拟机。 但是在我想把复制的镜像载入的时候&#xff0…

LINUX nohup命令输入输出深浅进出

无论是否将 nohup命令的输出重定向到终端&#xff0c;输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写&#xff0c;输出重定向到 $HOME/nohup.out 文件中。 AD&#xff1a;2013云计算架构师峰会课程资料下载 你可能会遇到nohup命令问题&#…

js获取年、月、日、时、分、秒

1 <SCRIPT LANGUAGE"JavaScript">2 var myDate new Date();3 myDate.getYear(); //获取当前年份(2位)4 myDate.getFullYear(); //获取完整的年份(4位,1970-????)5 myDate.getMonth(); //获取当前月份(0-11,0代表1月)6 m…

python __future__ package的几个特性

我学习python过程, 和学习其它编程知识一样, 不是先读大部头书系统学习, 而是看博客和直接实践, 慢慢将这些知识点连成线, 再扩展到面. 这个过程缺点和优点都很明显. 缺点是, 有些知识点可能因为一直没有机会碰到, 就一直是盲点, 另外从点到面过程较长. 好在我自学能力很强, 基…

(二) java版电子商务spring cloud分布式微服务b2b2c社交电商-Spring Boot配置文件详解...

Spring cloud b2b2c电子商务社交平台源码请加企鹅求求&#xff1a;一零三八七七四六二六。springboot采纳了建立生产就绪Spring应用程序的观点。 Spring Boot优先于配置的惯例&#xff0c;旨在让您尽快启动和运行。在一般情况下&#xff0c;我们不需要做太多的配置就能够让spri…