I am developing a cross-platform application with xamarin forms and I'm trying to run notifications on the various devices through the notification hub.
I encounter a problem when I try to send a test notification for the iphone.
The device can register the token, received by apns, on the notification hub even if only after the '<' and '>' and spaces are deleted, otherwise, the notification hub returns the error "one or more characters in device token is not a hexadecimal digit".
However, when I try to send a first test notification, Notification Hub returns:
"The test message has been sent. Outcome: {1 success, 0 unsuccessful}"
but notification never reaches the device. All the test notifications sent subsequently result:
"The test message has been sent. Outcome: {0 success, 0 unsuccessful}"
In fact, going to see the metrics in the notification hub the next day there are some
"APNS bad Channel Error"
So what could be the problem? Did anyone have the same problem? And what does "APNS bad channel error" mean?
The APNS Bad channel error indicates the device token you are using is no longer valid. Your app on the device needs to update the token on app. You can include that as part of application restart.
Also, regarding the notication not reaching the device. Can you make sure the device is switched on and notification are turned on. You can try to set the apns-expiration header to a longer value so that apns stores the notification for redelivery for a longer time.
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW13
Thanks,
Amol
Related
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.
I understand we can add code on iOS client side to detect whether the user has disabled push notification permission, my question it, is it possible to do it in only using APN?
I try the "Feedback Service" first, from Apple Programming Guide:
The Apple Push Notification service includes a feedback service to
give you information about failed remote notifications. When a remote
notification cannot be delivered because the intended app does not
exist on the device, the feedback service adds that device’s token to
its list. Remote notifications that expire before being delivered are
not considered a failed delivery and don’t impact the feedback
service. By using this information to stop sending remote
notifications that will fail to be delivered, you reduce unnecessary
message overhead and improve overall system performance.
FeedBack Service payload
So "Feedback Service" essentially give us a token list for failed push notifications. I tried to send push to a device with disabled push notification permission or app uninstalled , however my device token does not appear in this list.
Apple's document also mentions we will get immediate response from APN once we send the push notification:
If you send a notification that is accepted by APNs, nothing is
returned. If you send a notification that is malformed or otherwise
unintelligible, APNs returns an error-response packet and closes the
connection. Any notifications that you sent after the malformed
notification using the same connection are discarded, and must be
resent. Figure A-2 shows the format of the error-response packet.
However, it seems like the returned status stays the same no matter what I do: enable/disable push notification permission or even uninstall the app...
I fact, my hypothesis is that even the user has disabled the push notification, APN will still see it as a successful delivery, but iOS just simply don't show it. None of them response code from APN seem to be related to the disabled push notification.
I am wondering if there is a way to do it with APN? Thank you!
Reference: Apple Doc:https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html#//apple_ref/doc/uid/TP40008194-CH13-SW1
I'm sending iOS Push Notifications in the Enhanced Notification Format using PHP.
When I send the same message to the same device >= 600 times in a single connection, it sometimes fails at the 600th time with a status code 8 error (Invalid Token). The token is obviously valid since I'm receiving the notifications on a real device.
This happens on both the sandbox and production server.
What could be the cause of this? Is there a rate limit?
provided link possibly answers your issue.
it depicts there are max connections limit at once and DDOS behavior is also assessed possibly.
apple push notification limitation
When the device is off, I am sending push notification with expiry time to the device(IPhone).
If I have switched on the device before expiry time, I am able to receive the msg and no response from apple.
But If I have switched on the device after expiry time, Still no response from apple.
Is it possible to get the response saying "msg got expired" from apple?
No, the feedback service only indicates where you have attempted to deliver a notification to an invalid device ID. There is no indication available as to whether a notification was successfully delivered (or not) to a valid device ID.
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.