How to manage iOS apns token changes

烈酒焚心 提交于 2019-12-04 11:45:35

问题


I had an issue where a user started receiving double notifications after uninstalling and reinstalling my app, as the device sent to my server 2 different APNS tokens - one from the first installation and the other after reinstalling the app. Since the tokens were different I could not know this is the same device.

Until iOS 9 came out, every time I uninstalled and reinstalled the app, I always got the same APNS, so it was easy to know that this is the same device the user used as before. Since iOS 9, it seems that the APNS token is changed on every installation.

My question is how to tell if a client uninstall and reinstall the app, and update his APNS token instead of adding a new token?

I am asking as this sounds to me like something most iOS developers had to handle, but I couldn't find any best practice from Apple on how to tackle this, so I hoped that other can share their experience with this issue.


回答1:


This is how we ended up solving it:

On each app launch:

  1. create push notification token
  2. is there a token in localstorage?
    • yes - compare the tokens to localstorage. are they identical?
      • yes - return
      • no - update server with new token, and after server response with 'OK' save it locally in local storage and keychain
    • no - check is there a token in keychain
      • yes - compare the tokens to keychain. are they identical?
        • yes - save token in localstorage and return
        • no - update server with new token, and after server response with 'OK' save it locally in local
          storage and keychain
    • no - update server with new token, and after server response with 'OK' save it locally in local storage and keychain

If anyone has a more elegant way to solve it I would love to hear about it



来源:https://stackoverflow.com/questions/34280527/how-to-manage-ios-apns-token-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!