4

If I'm an Apple Push Notification "provider" for multiple iOS apps can I use the same device token for multiple apps? I'm aware that I need unique SSL certificates for each app. However I'm confused about the device tokens.

Example: I have two apps A and B. I want to provide push notifications for both apps. Say I collect a device token T from a user who installs app A. Assume I have unique SSL certificates for both apps. When the same user installs app B can I re-use token T when providing push notifications for app B?

More info: After re-reading Apple's docs it's still not clear. This paragraph in particular seems to imply the device token can be re-used:

Every notification that a provider sends to APNs for delivery to a device must be accompanied by the device token it obtained from an application on that device. APNs decrypts the token using the token key, thereby ensuring that the notification is valid. It then uses the device ID contained in the device token to determine the destination device for the notification.

Note: Sounds like the "topic"/bundleID contained in the provider's SSL certificate for each app directs the notifications to a particular app on a device. So it seems plausible that device tokens are unique for a device (and not for apps on the device).

SundayMonday
  • 19,147
  • 29
  • 100
  • 154

1 Answers1

7

For the two apps A and B the device token will be the same for sandbox ssl certificate, but it will change for distribution profile (i.e when using production ssl certificate)

Also, the device tokens might change when you upgrade the OS

I too have developed a "provider" and I prefer to store device tokens per app. i.e (APP_A => Token1; APP_B => Token1) Everytime a device sends a registration request to the provider, check if the combination of the APP and device token exists in the table, if not do a new insert.

This way you don't have to worry even if the device token changes for some reason.

makarand84
  • 111
  • 2
  • Interesting. Please provide a link to the relevant Apple docs. From the Apple docs I've read here [link](http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html) it sounds like the device token can be the same for both sandbox and production. – SundayMonday Nov 18 '11 at 20:27
  • I am not an iOS developer. This is something that I had learnt while implementing the provider server. – makarand84 Nov 18 '11 at 20:46
  • 1
    Here is one link... http://stackoverflow.com/questions/1943722/iphone-apns-device-tokens-in-sandbox-vs-production – makarand84 Nov 18 '11 at 20:47
  • Thanks for the link. I think I need to be more clear about my question. I'm interested in the device tokens I (as the provider) collect from the users of my app. Right now I'm not interested in the device token assigned to my device in development vs production. – SundayMonday Nov 18 '11 at 20:55
  • 1
    From what I understand, As a provider you want to re-use the Token T received from APP A to push notification to APP B installed on the same device. ?? – makarand84 Nov 18 '11 at 21:15
  • 2
    You can do so..but that is not the ideal way to do it. Consider I am a user and install App A, When I first start the app I will get a prompt asking if I want to allow push notifications for the app. If I select "Don't Allow" then your server will not receive the token. Hence you should not rely on one app to send token. Each of your apps, even if they are on the same device, should register their own tokens with the provider service. – makarand84 Nov 20 '11 at 06:50
  • I agree that it's probably best practice not to rely on a single app to send the token to be used with multiple apps. In the example above both apps A and B will prompt the user to allow push notifications. I'm wondering what happens when the user declines app A but allows app B. Will the user incorrectly start to receive notifications for both apps? Or just app B? – SundayMonday Nov 20 '11 at 15:35
  • 1
    If user does not allow notifications for App A, you should not be pushing the notification to that device for App A, even if you push, the apple push notification service will reject it. Also, I hope you are aware that the connections from your provider service to apple's service are per APP. So no chance of user incorrectly receiving notifications. – makarand84 Nov 21 '11 at 10:17