Question

Okay so im coding this app in iOS. Got the Push Notifications down pretty good. I just have one question. Would it be wise of me to store a users device token when they login and delete it when they logout, or keep it forever and basically only update it when a user logs in.

I guess what im seeking is.. best practices for storing and renewing device tokens.

My main issue is this.. when a user logs out... dont they expect to no longer receieve push notifictions. How does facebook approach this? From my understanding if i log out of my FB account through the FB app. It no longer sends me Notifications, am i correct? Im not a big FB user lol

Was it helpful?

Solution

I store mine using NSUserDefaults when the user logs in (and send it to my back end) and then delete it when the user logs out. Multiple reasons for this, A: It could change, there aren't really any specific docs saying if it will remain the same across devices with a backup/restore (but NSUserDefaults will). B. Also if a different user logs in on the same device you'll want the device token to then be connected to that user.

In the didRegisterForRemoteNotificationsWithDeviceToken you can check to see if the device token is the same as the one stored in userdefaults and update it if need be.

Generally speaking if the user logs out they no longer expect to receive notifications. And certainly if another user logs in on their device, they expect to receive notifications for that user. And yes this is how FB App works, or really any social media app. You wouldn't expect to get notifications if you are logged out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top