I have a strange case with APNS.
A user has two devices with the same Apple ID and our app installed. Both devices return the same APNS token to my app.
Whenever I try to send a push notification, the older device receives it, though we want the newer device (the one that the app was installed to recently) to receive it.
How do I achieve this?
Related
As far as I can read, it is technically possible to initiate an Apple Push Notification from an iOS App instead of via a server/service.
It would require the push notification certificate to be bundled with the app, and device tokens for the receiving devices must be exchanged.
Offhand this seems like a usable solution for some notification scenarios, but are there other limitations? Would such a setup not be accepted in an App submitted to the app store? Would exchanging device tokens pose some sort of risk? It would save the cost of a notification service and it would distribute the processing to the clients instead of the server.
What am I missing?
try NWPusher...
this is a third party but sends notification from ios to
How to avoid sending push notification to iOS app that is uninstalled.
Is there any way that we can catch application uninstallation event and call our server to stop sending notification.
What happens to the notification that is sent to device after the app is uninstalled.
Will old and new notification be available in the notification center even after the app is uninstalled.
Please explain.
The APNS Feedback Service exists for this purpose. When you connect to this service, you receive device tokens of devices that uninstalled your application, and you should stop sending push notifications to such device tokens.
When you send a notification to a device that uninstalled the app, Apple logs the device token and will send it to you the next time you contact the Feedback Service.
When you call the APNS service ,you will receive uninstalled app's device tokens.
After that checking those device token, you should stop sending push notifications to those device tokens.
Hope this help.
By that I mean: If you have an app running on both platform, can you be sure that a given token on iOS isn't attributed to Mac? I'm pretty sure this isn't something we can "know" (Apple internal) and I shouldn't assume it, but I'm really curious what happens if you (by mistake) send an "iOS" Push (intended for your iOS App) to a Mac token. Could it reach another iOS user?! I guess potentially...
Imagine the following case (simplified):
You know you have to send a push to the token "foo" to your Mac app.
You mistakenly send a push to "foo" on your iOS app.
I hope it would land in void land / you'd get an error back from APNS but I guess it might also land on a "random" user of your iOS app, which is not the user intended (on the Mac app)
Sending a push notification requires an SSL certificate from Apple that is bound to your iOS or Mac application. Therefore it can not happen that a notification for an iOS app is sent to a Mac app.
From the following quote it doesn't seem possible that the same device token will be assigned to both an iOS device and a Mac (or to two iOS devices or to two Macs), since device tokens contain device IDs, and device IDs should be unique (otherwise they wouldn't be very useful IDs).
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.
(Source)
I was testing my iOS app I found one interesting thing that even my phone is in airplane mode and I have also switched off WIFI, my app is able to receive the the Device Token after registering for push notification.
I have also tried even after removing app and its associated certificate from the iPhone.
but got same results.
How is it possible, any idea ?
thanks in advance.
This is from the APNS programming guide :
By requesting the device token and passing it to the provider every
time your application launches, you help to ensure that the provider
has the current token for the device. If a user restores a backup to a
device or computer other than the one that the backup was created for
(for example, the user migrates data to a new device or computer), he
or she must launch the application at least once for it to receive
notifications again. If the user restores backup data to a new device
or computer, or reinstalls the operating system, the device token
changes. Moreover, never cache a device token and give that to your
provider; always get the token from the system whenever you need it.
If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system
passing the device token to the delegate immediately without incurring
additional overhead.
It implies that if your application is already registered for push notifications, calling the registerForRemoteNotificationTypes doesn't access the APNS server.
The fact that you uninstalled the app doesn't unregister it from APNS. You can prove that to yourself by calling the feedback service immediately after uninstalling the app. You wouldn't get the device token from the feedback service in this case, because the APN service doesn't know you uninstalled the app. Only if you send notifications to the device after uninstalling the app, the APN service will know the app was uninstalled.
How can I get a notification from App Store or APNs when my iOS App gets uninstalled?
Also, if I send a push notification for the device where my App is uninstalled, what happens? Will Apple ban for such rogue Push notifications?
There isn't a way that your app will know if it is uninstalled. Also I do not believe there is anyway Apple will tell you if your app is uninstalled.
Apples Push Notification Service's FeedBack Service does provide a way to know if a device cannot receive a notification. However this does not guarantee that the device was uninstalled, only that it, for whatever reason, can not receive push notifications.
If a provider attempts to deliver a push notification to an application, but the application no longer exists on the device, the device reports that fact to Apple Push Notification Service. This situation often happens when the user has uninstalled the application. If a device reports failed-delivery attempts for an application, APNs needs some way to inform the provider so that it can refrain from sending notifications to that device. Doing this reduces unnecessary message overhead and improves overall system performance.
For this purpose Apple Push Notification Service includes a feedback service that APNs continually updates with a per-application list of devices for which there were failed-delivery attempts.