iospush-notificationapple-push-notificationsdevicetoken

Obtain NEW Apple device token?


I am creating an app that allows the user to log out of the app and log in as different user if they want to. Is there any way to obtain a new device token from Apple once the new user logs in? Is there a way to force call the didRegisterForRemoteNotificationsWithDeviceToken method?


Solution

  • No, you can't request a new device token. They expire from time to time, and only then will you get a new one (or if you have a different app with a different bundle id, the token will be different).

    Create a function to handle didRegister and call that from didRegisterForRemoteNotificationsWithDeviceToken. Then use that function when you need to force the call.

    Since users are logging in, pass the information with the device token to the server every time someone logs in and associate the user to the token on the server side.