1

After google the question, it makes me confused. Does every app in iOS has the same DeviceToken?

Here is the Apple Document about the issue.

A device token is an opaque NSData instance that contains a unique identifier assigned by Apple to a specific app on a specific device. Only APNs can decode and read the contents of a device token. Each app instance receives its unique device token when it registers with APNs, and must then forward the token to its provider, as described in Configuring Remote Notification Support. The provider must include the device token in each push notification request that targets the associated device; APNs uses the device token to ensure the notification is delivered only to the unique app-device combination for which it is intended.

Saad Chaudhry
  • 1,392
  • 23
  • 37
Ran
  • 303
  • 1
  • 3
  • 15
  • Each app instance receives its unique device token when it registers with APNs --- Written Clearly – Saad Chaudhry Feb 27 '18 at 09:36
  • NO, DeviceToken change frequently – iParesh Feb 27 '18 at 09:37
  • @SaadChaudhry I thought they have same token and when the provider push notification, apple apns distinguish different app with bundle identifier – Ran Feb 27 '18 at 09:42
  • @iParesh i know ,when update apps or update ios,it changes. but does facebook and instagram have same token? – Ran Feb 27 '18 at 09:43
  • @Ran Both are different device token – iParesh Feb 27 '18 at 09:46
  • https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW13 – Saad Chaudhry Feb 27 '18 at 09:46
  • @iParesh I mean the (NSData *)deviceToken, not Bundle identifier – Ran Feb 27 '18 at 09:51
  • @RanJi As several people have said, every app on a device gets its own device token. So Facebook has one, Instagram has a different one and your own developed app gets it own. No apps share the same device token. – Hodson Feb 27 '18 at 10:05
  • the APNs token is __globally unique__ in Apple's ecosystem for each installation of the app on each device; which means in practice your app's token will be completely different even after the user just reinstalls your very same app on the very same device. – holex Feb 27 '18 at 10:21

4 Answers4

4

No, each app will get its own device token.

Also note that the device token assigned to the app/device can and does change from time to time which is why you always need to send the updated version to your push server and/or any other services that may make use of the device token.


A bit of clarification on the device token changing "from time to time":

Meaning of "from time to time" is "sometimes, but not regularly"

Taken form the Apple Documentation:

Never cache device tokens in your app; instead, get them from the system when you need them. APNs issues a new device token to your app when certain events happen. The device token is guaranteed to be different, for example, when a user restores a device from a backup, when the user installs your app on a new device, and when the user reinstalls the operating system.

Hodson
  • 3,438
  • 1
  • 23
  • 51
  • what does that _"does change from time to time"_ mean exaclty? where does such speculation come form? the token is not going to change as it goes along out of blue _time after time_, so can you elaborate, please? – holex Feb 27 '18 at 10:27
  • Updated the answer to add some clarification @holex – Hodson Feb 27 '18 at 10:33
  • you could quote this, it is a much simpler explanation: _"Receiving, via APNs, globally-unique, app-specific device tokens and other relevant data from instances of your app on user devices."_ ([source](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1)) – holex Feb 27 '18 at 10:38
2

Each app has different device token.

A device token is an identifier for the Apple Push Notification System for iOS devices. Apple assigns a Device Token on a per-app basis (iOS 7 and later) which is used as a unique identifier for sending push notifications. Each device has two device tokens per app: one for development, and one for production (ad hoc or app store builds). The tokens are 64 hexadecimal characters.

PPL
  • 6,357
  • 1
  • 11
  • 30
  • so when push me a notification , the provider must give apple two parameters, the app unique token and app bundle identifier? – Ran Feb 27 '18 at 09:45
  • @vikingosegundo APNs device tokens are of variable length. Do not hard-code their size. – Saad Chaudhry Feb 27 '18 at 09:46
  • "device token is an identifier" is it the Bundle identifier? I mean (NSData *)deviceToken – Ran Feb 27 '18 at 09:50
  • No it is not bundle identifier, it is 64 hexadecimal character's string – PPL Feb 27 '18 at 09:52
  • @RanJi see this https://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0 – PPL Feb 27 '18 at 09:54
1

Each app instance receives its unique device token when it registers with APNs.

HeroG
  • 20
  • 6
1

Each app has different device token. That will generate while you register for push notification.

If you reinstall app then also you will get different device token for the same app on the same device.

Tejas Ardeshna
  • 4,343
  • 2
  • 20
  • 39