问题
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).
回答1:
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.
来源:https://stackoverflow.com/questions/8188274/device-tokens-for-apple-push-notifications-provider