I have an iOS application where users can log in and out with different accounts. (These accounts are specific to our Service).
I am also using APNs to push notifications from my backend server to the application, when something intreresting has happened.
The following scenario describes my problem:
Has anyone solved a similar problem? I can think of several solutions such as:
None of these solutions seems optimal and I haven't found anything better. I think that for example Facebook must have solved a similar problem and probably many others too.
Thankful for some input on this.
FYI. I will face the exact same problem on Android, but I have chosen to separate the Questions here on Stack Overflow.
The push notification networks identify each device by device token. A device token is not a device IMEI but an ID to identify a certain mobile app on a certain device. It is issued by calling libraries of FCM, JPush, or APNs.
APNs issues a new token when the user restores a device from a backup, when the user installs your app on a new device, and when the user reinstalls the operating system. If you ask the system to provide the token each time, you're guaranteed to get an up-to-date token.
Whenever your Application is installed first time and open, MyFirebaseMessagingService created and onNewToken(String token) method called and token generated which is your Device Token or FCM Token.
did you find the silver bullet for the issue? The way we resolved the problem is the following:
When logging out we unregister from remote notifications to make sure no push notifications will be received.
UIApplication.shared.unregisterForRemoteNotifications()
P.S.: The Android part is easier because you can access the token at any time through the lifecycle of the app, therefore, you don't have to store it manually.
The 3rd solution is the good one. You just need to delete the installation object in your backend when the user logs out, and create a new one at log in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With