views:

32

answers:

2

Hi,

I have to developp an app that uses Push Notification in a particular way, and I had a pretty tricky question : can the device token be stored locally in the app sandbox? Here's the why : this app should implement a notification system that allows the user to subscribe for some particular events only, from the iphone. So to do so, I need to send to my database the Device Token of the iPhone at any time when the app is running, and from what I get, the device token is only avaliable when the

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

is called right? Or is there any way to retrieve this information later?

Thanks.

+1  A: 

You should store it somewhere on the phone. NSUserDefaults is a decent place to do it since it's not a big piece of data and you can retrieve it easily afterwards. I would also recommend saving it on your server, and only updating it if the token changes.

Elfred
Apple won't reject my app because I store the tolen locally?Thanks for your insights ;)
radada
No, you won't get rejected. s mentioned, it needs to get stored on the server as well, since you need to know where to send the notification.
Elfred
A: 

The push notification programming guide however recommends you not to store the token locally:

"An application should register every time it launches and give its provider the current token. It calls registerForRemoteNotificationTypes: to kick off the registration process."

"By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. If a user restores a backup to a device other than the one that the backup was created for (for example, the user migrates data to a new device), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in iOS passing the device token to the delegate immediately without incurring additional overhead."

Andreas