溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS Device token的問題

發(fā)布時間:2020-07-21 21:41:42 來源:網(wǎng)絡(luò) 閱讀:1471 作者:無名小卒 欄目:移動開發(fā)

Device token for an iPhone device生成之后就永遠(yuǎn)不變嗎?

不是,if a device is wiped (應(yīng)該是重裝系統(tǒng)), it will get a new device token. 

官方網(wǎng)站是這樣寫的: 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  里)調(diào)用registerForRemoteNotificationTypes來獲取device token以檢查device token是否改變,如果改變了就應(yīng)該把新token傳給push provider。(官方描述:An application should register every time it launches and give its provider the current token)

device token應(yīng)該存儲在NSUserDefaults來達(dá)到新舊比較的目的

那么舊device token在push provider對應(yīng)的record怎么辦?

方案1:把舊device token send to provider and request delete record

方案2:使用apns feedback service。

方案2可能更好些,因為總是需要使用apns feedback service來處理用戶在device里刪除app的情況。


調(diào)用registerForRemoteNotificationTypes方法后,成功注冊后,APNS就會返回一個device token,然后回調(diào)delegate methoddidRegisterForRemoteNotificationsWithDeviceToken, 如果注冊失敗,則回調(diào)delegate method didFailToRegisterForRemoteNotificationsWithError。

注意:

* 在第一次調(diào)用registerForRemoteNotificationTypes方法沒有聯(lián)網(wǎng),則既不會調(diào)用didRegisterForRemoteNotificationsWithDeviceToken,也不會調(diào)用didFailToRegisterForRemoteNotificationsWithError

*第一次調(diào)用registerForRemoteNotificationTypes注冊成功后,之后即使沒有聯(lián)網(wǎng),再調(diào)用registerForRemoteNotificationTypes時都會以最上一次的device token作為參數(shù)回調(diào)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.


上述東東參考官方網(wǎng)站關(guān)于Registering for Remote Notifications的講解


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI