1

To my knowledge, once we got the device token from APNS, we can't get it again. (Except that backup data to a new device or computer, or reinstalls the operating system or any time the device token changes which will call the didRegisterForRemoteNotificationsWithDeviceToken)

So,

Any time the device token changes , i will replace and save the new device token in the keychain to avoid it disappears for other purposes (likes use device token to the UUID).

  1. Is it possible when the keychain data disappeared, but device token not changes?

    ( If yes. It will lead to the didRegisterForRemoteNotificationsWithDeviceToken not called again,and can't retrieve the last device token. )

  2. Or the events let the keychain data disappeared also(generally) let the device token changed (or trigger didRegisterForRemoteNotificationsWithDeviceToken again ) ?

    In my test,

    A. "Reset All Settings" in iPhone will not clear the keychain data and trigger didRegisterForRemoteNotificationsWithDeviceToken.

    B. "Erase All Content and Settings" in iPhone will clear the keychain data and remove all your apps. So when re-install the app that will call didRegisterForRemoteNotificationsWithDeviceToken again.

    Case A and B not bother me, and i think that updating the os version, reinstalling the os or any event let the device token changed also.

  3. Anyone knows the correct corresponding state of value change between keychain and device token ?

Thanks!!

Update

The question is any event lets the keychain data disappeared also(generally) triggers the "didRegisterForRemoteNotificationsWithDeviceToken" againg or not?

If not, which event?

user3365407
  • 53
  • 1
  • 9
  • you can get device token when you need.. and didRegisterForRemoteNotificationsWithDeviceToken called in your need also. – Max Oct 10 '14 at 12:07

2 Answers2

2

"To my knowledge, once we got the device token from APNS, we can't get it again"

When your app loads, you call

[[UIApplication sharedApplication] registerForRemoteNotifications];

this leads to your app delegate method:

- (void) application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token

being called. The token is handed to you each time your app runs. You shouldn't need to store in the keychain.

You do of course need to send the token value to your back-end so that it can be used to originate push messages.

CSmith
  • 13,318
  • 3
  • 39
  • 42
  • Thanks. But in my case, i use the device token to be the UUID for querying some data from my back-end. So it must be saved in keychain. Because the device token not changes, the "didRegisterForRemoteNotificationsWithDeviceToken:" not be called again.(Document said). Then last device token can't be retrieved when keychain disappeared. – user3365407 Oct 11 '14 at 07:15
0

One suggestion comes to my mind is using NSUserDefaults to store the device token and then retrieving it from there and sending it to the back-end every time the app starts in appDelegate.m

allwynmasc
  • 393
  • 5
  • 18