when to properly store or delete users device token
Asked Answered
D

1

5

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

Dynast answered 31/5, 2013 at 18:4 Comment(0)
S
7

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.

Spies answered 31/5, 2013 at 18:7 Comment(2)
Great explanation that really helps me out. I expected as much, but wasnt 100% sure. Thanks!Dynast
Actually there are docs now from Apple saying never cache the token locally. see the yellow "Important" box at developer.apple.com/documentation/usernotifications/…Civil

© 2022 - 2024 — McMap. All rights reserved.