I have a general question to device tokens for push notifications.
this is a part of the apple documentation:
A device token is not a unique ID that you can use to identify a
device. Device tokens can change after updating the operating system
on a device. As a result, apps should send their device token
I understood that each app on a device get an unique token.
For example, the token of a app on my device is XYZ
With this token I can send from my server an push notification to XYZ and I will received it on my device.
According to Apple, the device token can change after an OS update
but what happens if the device token of my device changes and I don't start the app for a few days, so that the new device token isn't in my token table in my database?
What will be happen with the notification, which I will send to the old device token?
Related
When working with push notifications via the Apple's APN service, when my app is installed and the user opts into receiving push notifications a device token is generated.
Is this device token unique to every single device or is there a global device token I can use to send push notification messages?
I am guessing if the device token is unique, I would have to save it up to a DB.
Well, Device token is unique but it become change when you reinstall it from appstore. You have to store that Token in database to send notification through that token. It should automatically register in database after installing with first time opening the app, It always hit but your database code should not reinsert it if same device token string found in the database.
NOTE: Device Token, UDID and UUID all are different and unique with some different usage purposes.
Is there any possibilities for a device token to change after the app is installed and registered for the notification in any kind of scenarios.
Scenarios like:
App update
iOS update
or in any other random scenario's.
Previously in document it was like,
If the user restores backup data to a new device or reinstalls the
operating system, the device token changes.
From new documentation here:
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html
Important: To protect user privacy, do not attempt to use a device
token to identify a device.
APNs can issue a new device token for a variety of reasons:
User installs your app on a new device
User restores device from a backup
User reinstalls the operating system
Other system-defined events
As a result, apps must request the device token at launch time, as described in APNs-to-Device Connection Trust and Device Tokens.
I have been developing an iOS app, which is sending remote notifications. For that I am saving the device token on our server. When the user logs in to our app, the device token saves on our server and remote notifications work fine.
But after some time, the notifications stop coming. I think it's due to that the device token changes but doesn't get updated on our server. I studied Apple's document on remote notifications; it says that if the device token ever changes, then it is the responsibility of the iOS to call the
didRegisterForRemoteNotificationsWithDeviceToken
of the app delegate with the updated device token. I have written the code to save the device token to our server in this method, but the device token does not change and remote notifications do not come.
Do I have to update the device token myself? If yes, then where to do that?
iOS Device Token for the push notification is an opaque identifier of a device.
The provider can't get any device related information from the device token.
Based on Apple Push Notification programming guide, the provider needs to provide device token and payload to APNs server for the push notification.
Can provider send phone number OR bundle id OR advertising identifier OR vendor identifier to the APNs Server when the provider send token and payload to APNs server during push notification ?
So, the APNs server will not send the message to device if the device token is not associated with any device properties (like phone number or advertising identifier or vendor id).
I think you answered your own question:
Based on Apple Push Notification programming guide, the provider needs to provide device token and payload to APNs server for the push notification.
If you could provide the phone number, for example, you could simply use harvested phone numbers and spam people with push notifications. The token is not only for identifying the phone; you only get one if the user explicitly said "Yes, I want push notifications."
The only properties that determine if a push notification is delivered to an iOS application on a given device are the push certificate used to establish the connection with APNS (which determines the destination application) and the device token (which determines the destination device). Any other parameters you choose to include in your payload will have no effect on the delivery of the message.
The solution that we implemented (and it works very well), is:
have the device token sent to the server upon registration
server stores that in a 'user_device' table (which ties the user to the device - once you get the info.... at this time you only have the token, so the userId is 0)
the user continues with their login info.....
as the user completes their login (going to the server for verification), include the token and match that up in the database (note that you could also just send it at this point, but we like to send the token in #2 so we could see how many people register devices but not log in...)
Now, you have a match-up from the user data to their deviceId and can then match up various USER properties (or even the device properties if you have gotten them from other means - like when the user signed in and completed their profile) and send the appropriate push notice.
is device token changes each time when i opens my application?
Apple server uses the same device token every time or the new regenerated device token?
You can check developer documentaion, following is mentioned there -
The form of this phase of token trust ensures that only APNs generates the token which it will later honor, and it can assure itself that a token handed to it by a device is the same token that it previously provisioned for that particular device—and only for that device.
If the user restores backup data to a new device or reinstalls the operating system, the device token changes.
So they are uniques to iPhone until OS is reinstalled.
You can check details here - http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW12