天天看點

iOS8推送消息、注冊通知

1、ios-push-notifications

https://parse.com/tutorials/ios-push-notifications

2、iOS8推送消息的快速回複處理

http://blog.csdn.net/yujianxiang666/article/details/35260135

3、iOS8注冊通知

http://blog.csdn.net/apple_app/article/details/39228221

4、Device token的獲得和改變詳解 

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的講解

繼續閱讀