How new GCM handles APNS feedback? - ios

I was trying out new GCM feature to send notifications to iOS devices. Everything worked very smooth except the feedback message. I assume after GCM sends message through APNS, GCM also calls feedback service of APNS to get the invalid tokens. Next time when we use the same device token to GCM, it should respond with error message. I tried several times after uninstalling the app, but never received an error message from GCM. Each time it shows success message. What went wrong here?
Note: If you are not familiar with new GCM features, please do not blindly answer to this.

I think the problem here is with the environment. I am using developer certificate to test the notification. APNS may not be giving any details for developer environment. Hope it will work in production.
Updates
Support from Google gave following details.
We did some digging, it seems that is how things are being handled by APNS:
When last sandbox app is removed from the device, device disconnects from APNS sandbox and not able to receive pushes/provide feedback anymore. Thus, APNS feedback doesn't register that the device has been uninstalled.
If you install another push-enabled sandbox app on the device, which would force device connection to APNS again. And we checked that under this circumstance, we get notified that the device has been uninstalled and return NotRegistered to our client.

APNS feedback service is not instantaneous. GCM does poll APNS feedback service but in my experience it was a bit delayed (not sure if it was APNS's delay or GCM's delay).
You should wait for some time and then try to use an old registration token and you should see a "Invalid Registration Token" error.

Related

VOIP token won't get invalid after uninstalling an app from a device or disconnected from the network in iOS

I am working on one VOIP-based application where one user calls another user everything works fine like calling and all.
But whenever I didn't log out from the application and directly uninstall the application at that time any another user tries to call the user who already uninstalled the application. At that time backend get a successful response from apple (i.e. 200 Success). Why won't give an error if that app is not installed
Actually, we need to give some specific alert to the user who called the person who already uninstalled the application but we are unable to find from backend too that the voip push failed.
One another thing just for testing : We tried to send FCM silent notification too which works synchronously with VOIP notification but in that too FCM gives success in backend while app already uninstalled from device.
If anyone facing same issue and having solution regarding that then please let me know.
In the short term, Apple doesn't know that the user has uninstalled the app, so it accepts the push.
Pushes are delivered asynchronously (Since a device may be offline when you send the push; it will be queued for delivery later).
The APNs cannot provide immediate feedback on the delivery of your push. The 200 status simply means that the push was successfully accepted for delivery.
Eventually Apple will determine that the push token is invalid and return a 410 response. At that time you can remove the push token from your database.
In the short term you can detect if the device doesn't respond to the VoIP push in a reasonable time frame and return a "call failed" or "recipient unavailable" response to caller.

FCM notifications sent but never received in iOS

Update...before I ever posted
I actually discovered the solution before I posted this but thought I'd post it anyway in hopes of saving someone else's time.
As a last resort I tried deleting the APNs Authentication Key and reverting back to the certificate for the application in Firebase Cloud Messaging project settings. That fixed it. Below is the message I'd intended to post.
I'm attempting to push notifications to subscribers of a specific topic using Firebase FCM. According to the Cloud Messaging console the notifications are being sent but they're never received by a device subscribed to the topic. I'm also not receiving test messages sent via the console.
I've confirmed the following:
APNS is properly configured for my project. I was able to receive a
notification on a device using a testing site
(https://www.apnstester.com/apns/)
The topic is being subscribed to or at least subscribeToTopic doesn't
return an error.
I'm receiving a remote instance ID token.
I'm receiving an APNS device token
I've also tried:
Enabling and disabling swizzling (and yes, when it's disabled I'm
setting the APNS token)
Deleting and reloading my APNs Authentication Key
Updating the Firebase framework
Removing and re-adding the GoogleService-Info.plist
I should point out this is old app (hence the Objective-C swizzling) and notifications worked fine in the past. Any suggestions or advice?

Diagnosing dropped notifications from Azure Notification Hub to APNS

We have a (mostly) successful implementation of push notifications to iOS and Android devices through Azure Notification Hubs.
The problem is that some of the iOS devices are apparently never receiving notifications that are sent by Azure Notification Hubs.
We use templates and tags to direct the messages to the appropriate devices. The tags are interest topics, and never user-specific, so we're expecting one notification for a tag to be pushed to all devices subscribed to that tag.
The Android devices seem to receive their notifications flawlessly, but the iOS devices are not consistent. Most of them work. A couple do not.
We are well aware that push notifications are delivered with best effort and have no guarantee of reliability, but our limited testing has revealed more devices which consistently fail to receive push notifications than seems unreasonable (more than two failures from about a dozen devices).
Here's the setup:
We have a simple C# routine in the back end which connects to Azure Notification Hubs and sends notifications to Azure:
var outcome = await hub.SendTemplateNotificationAsync(properties, tag);
We have used the GetAllRegistrationsAsync method to make sure that every device we are checking has successfully registered and is using the correct template. Every device is registered, all the templates are correct.
We are not in "test mode"; the enableTestSend parameter of NotificationHubClient.CreateClientFromConnectionString is set to False.
Troubleshooting:
When we send the notification out, most devices receive the notification and, in the specific case we're testing, update the badge counter with the correct number.
However, a couple of devices do not seem to get the notification. One of the devices did get the notification after we rebooted the device, but after that it stopped.
Using the above mentioned GetAllRegistrationsAsync method, we have verified that the problem devices are correctly registered on Azure and have the correct tags and templates.
We were able to determine the device tokens of the problem devices from the Azure registrations. We used a PHP script which communicates directly with APNS to send a notification just to the problem devices using their device tokens. Every time, the device receives this direct-send notification. It's only the notifications from Azure which are unreliable.
When we examine the Azure Notification Hub Monitor page, we see these metrics for the past 24 hours:
967 APNS Successful Notifications
3 APNS Bad Channel Errors
2 APNS Expired Channel Errors
4 APNS Errors
... and no other errors reported for APNS or for Azure in general. The failure rate we're seeing should have produced an error count over 20.
We have not been able to determine which device tokens were responsible for the errors; is there a way to get this information from Azure?
We're at a loss to explain why we can send notifications directly to these devices over APNS itself, but not through Azure, and why it is that Azure doesn't report more errors than it does.
Any suggestions or insights?
It's quite possible that you have some sandbox device tokens in your database (I'm not sure if the device tokens are stored in your server or in Azure Notification Hub). When trying to send a notification with a sandbox device token to the production push environment, an InvalidToken error is returned by Apple, and the connection is closed.
Very often, by the time the server that sends push notifications to Apple's APN server gets the error response, it has already sent many more notifications (possibly with valid tokens), and all of which are discarded by Apple. At this point, new notifications are accepted by Apple only after a new connection with APNS is established, so messages that were sent after the invalid token to the old connection need to be resent. It is possible Azure don't handle this resending correctly.
As you said, the Azure Notification Hub Monitor page shows a few errors. I suspect that 3 APNS Bad Channel Errors means invalid device tokens. I don't know how many invalid device tokens you actually have in the DB, but even one can cause many notifications with valid tokens not to be accepted by Apple.
The best solution is to test all the device tokens in the DB and figure out the ones that are invalid and delete them.

I need to test if I have registered for push notification correctly and I receive remote notification

I need to test if device token is received properly (if registration is successful), notification is received and badge count is updated in simulator. I know that we cant use push notification from simulator and check if badge count is updated from simulator. But my question is, will I be able to test by connecting with my device and debug from Xcode. Or Is there any other way to check before giving a beta test.
I have got the development and distribution (ad hoc) provisioning profiles.
I checked if push notification is enable in these profiles.
I use development to debug from simulator using device.
I followed all the steps required to set push notification from app side.
Is there a way to send notification manually and check if its received properly. Since the changes in the server are not yet completed I need to check it from app side.
Somebody please help me out.
Thanks in advance.
Yes, you can connect your device and debug from Xcode. You'll be able do see if the registration to APNS succeeded or failed based on the callback method being called (either the one that returns the device token or the one that indicates an error).
However, you can't send a notification without the server side. Well, technically you can, but it will be as complicated as implementing the push at the server side (you'll have to establish a TLS connection with APN server and send a notification in the binary format that Apple expects), and probably more complicated, since you'll have to implement it in Objective C.

APNS (Apple Push Notification Service) reliability

Our app uses APNS to receive Push Notifications. However, our client claims that some of their devices were not receiving notifications and argues to they 'must' make sure the notifications to be delivered 100%. But I have read somewhere that APNS is not 100% reliable and there should be cases which the notifications are not delivered.
I'm currently panic at how we could make sure APNS to received anytime. I have read that a case which may APNS not delivered (device may offline). But our test showing that even the device is online (Wifi or 3G), sometimes APNS were not delivered.
Is there any specific case which may APNS will not delivered? Or is there anything we (developers) can do with codes to make sure to receive all notifications? What I have done in the code is just registering the app to remote notification and write didRegisterForRemoteNotificationsWithDeviceToken, then throw the device token to our server.
Any help would be appreciated, for our client almost kill us if ALL of their devices not receiving APNS!
APNS is based on Apple Servers, and Apple doesn't give any guarantee on successful message delivery.
If the app is open (i.e. the user is using the app) while the notification arrives, iOS doesn't show a notification message, you need to handle it.
Notification shows up only when the app is backgrounded or killed.
Also implement feedback service on your server side; will help you get rid of old unwanted tokens (users who deleted the app or disabled notifications through settings).
Don't send too many notifications to a device within a short span of time, because APNS caches only 1 message/device (if the device is offline). So it can deliver the message when the device comes online. Am not sure how long the message is cached though.
Or just implement Pusher... http://pusher.com
We're facing the same problem. As everybody said, APNS is a best effort service so you can't be sure every notification will be delivered, but what you can do is to be sure of which ones have been received. This is what we're about to do. We register in our backend each notification que ship and the mobile app reports back each notification it receives. Then we set a maximum time of waiting for a notification to be received, if we don't receive the report back we try again.
I hope it might be helpful to someone (even 2 years later)
It says it quite clearly in the Apple Docs that it is not 100% gauranteed and nor should it be used as so. Its sent with "best effort".
As per Apple's guidelines, APNS is not 100% reliable service which means your app may not get push notifications from Apple servers due to some of the following reasons:
Device is offline
Your app is in the foreground state, you need to manage the push notification.
Note: Apple rejects apps which make compulsion to use notification services. (I have faced it in one of my App)
For more information, you can look into this answer
https://stackoverflow.com/a/25830955/3278326

Resources