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
Related
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
We use push notifications in our app. They work, but there's some variable delivery delay (sometimes ~10seconds, sometimes more than minute).
Does anybody know what to do to minimize those delays?
I know APNS has some delay, but I've never experienced such slow deliveries.
EDIT:
I digged out some time delay between message sent date and push created date.
I have message sent at 12:40:17 (according to QB's admin panel)
and push notification log for the same message says the the push is: "created_at":"2016-05-12T12:40:28Z"
Clearly we have 11 seconds difference between the time message is sent to QB and push notification being sent to APNS from QB
Push notifications are unreliable and cannot be guaranteed that they have been delivered. It all depends on the apple APNS server, that said, usually when I send a push notification I get the result in under a few seconds.
They are not reliable! ****There is no guarantee that push notifications will actually be delivered, even if the APNS server accepted them****.
As far as your server is concerned, push notifications are fire-and-forget; there is no way to find out what the status of a notification is after you’ve sent it to APNS. The delivery time may also vary, from seconds up to half an hour.
Also, the user’s iPhone may not be able to receive push notifications all the time. They could be on a WiFi network that does not allow connections to be made to APNS because the required ports are blocked. Or the phone could be turned off.
APNS will try to deliver the last notification it received for that device when it comes back online, but it will only try for a limited time. Once it times out, the push notification will be lost forever!
For what it's worth I am running into this issue too with Quickblox. The push notifications, a critical part of the communication flow, are delayed by up to a minute or so. I use push all the time in enterprise apps and yes, they should not be considered reliable, but in practice APNS communications are remarkably reliable and near instantaneous in my experience. It seems like Quickblox is queuing (throttling?) notification requests, my guess is to conserve bandwidth - aren't they based in Russia? It's spoiling what would otherwise be a great product.
Is it possible to send multiple (10 - 15) notifications to the registered iOS users at a time / instantaneously ? What are the limitations for iOS Push Notifications ?
Is it possible to send multiple (10 - 15) notifications to the registered iOS users at a time / instantaneously ?
No you can not send 10-15 notification simultaneously to same user, read more here at apple docs .
If you are sending multiple notifications to the same device or
computer within a short period of time, the push service will send
only the last one.
However if you intend to send push notifications to different users at same time than it should be no problem (Which i guess is what you are looking for).
What are the limitations for iOS Push Notifications ?
If you are not sending them simuntanously to same user than there is no limitation for APN's push notification as mentioned here .Take a look at Push Notification Throughput and Error Checking
There are no caps or batch size limits for using APNs. The iOS 6.1
press release stated that APNs has sent over 4 trillion push
notifications since it was established. It was announced at WWDC 2012
that APNs is sending 7 billion notifications daily.
If you're seeing throughput lower than 9,000 notifications per second,
your server might benefit from improved error handling logic.
Here's how to check for errors when using the enhanced notification
format. Keep writing until a write fails. If the stream is ready for
writing again, resend the notification and keep going. If the stream
isn't ready for writing, see if the stream is available for reading.
If it is, read everything available from the stream. If you get zero
bytes back, the connection was closed because of an error such as an
invalid command byte or other parsing error. If you get six bytes
back, that's an error response that you can check for the response
code and the ID of the notification that caused the error. You'll need
to send every notification following that one again.
Once everything has been sent, do one last check for an error
response.
It can take a while for the dropped connection to make its way from
APNs back to your server just because of normal latency. It's possible
to send over 500 notifications before a write fails because of the
connection being dropped. Around 1,700 notifications writes can fail
just because the pipe is full, so just retry in that case once the
stream is ready for writing again.
Hope this helps.
If you are sending multiple notifications to the same device or computer within a short period of time, the push service will send only the last one.
Here's why. The device or computer acknowledges receipt of each notification. Until the push service receives that acknowledgment, it can only assume that the device or computer has gone off-line for some reason and stores the notification in the quality of service (QoS) queue for future redelivery. The round-trip network latency here is of course a major factor.
As described in the Local and Push Notification Programming Guide, the QoS queue holds a single notification per app per device or computer. If the service receives another notification before the one in the queue is sent, the new notification overwrites the previous one.
All of this points out that the intent is that a notification indicates to an app that something of interest has changed on the provider, and the app should check in with the provider to get the details. Notifications should not contain data which isn't also available elsewhere, and they should also not be stateful.
Any push notification that isn't delivered immediately was queued for future redelivery because your device was not connected to the service. "Immediately" of course needs to take latency for your connection into account. Outlying cases would be beyond 60 seconds as APNs will time out at that point.
for more info click here
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'm currently using Pushwoosh as my push notification provider for iOS push notifications. What I'm noticing is that it takes on average 10-15 seconds to receive notifications after they are sent out. What I want to know is if this number is a normal number given the amount of traffic that Apple receives to their APNS servers? What kind of speeds do you get using Pushwoosh or other services? Is it time to switch to something more reliable, or is this just the nature of APNS no matter what provider I go with?
Pushwoosh is very cheap and affordable, but I'm starting to realize you get what you pay for, and that's not quality.
There are several possible problems
Your connection to pushwoosh.Just ping Pushwoosh API gateway cp.pushwoosh.com
Some delays on pushwoosh side.Send message, then go to https://cp.pushwoosh.com/notifications and find your message in the list, it must be first from the top. Status of the message can be pending, processing or done. In pending status your message is not being sent right now. It means that pushwoosh servers are currently very busy(really rare situation). When status becomes "processing", pushwoosh starts sending notifications to APNS immediately. In normal situation you should receive notification before your message becomes "done" in pushwoosh control panel. if not, see 4
Device connection.Even if you are sure that your device is connected to the internet - check again. This is the most common problem with delays.
APNS delays.I do not know 100% way to diagnose this, but if message status in pushwoosh control panel is "done" and you are sure about (3), there are some delays on APNS.
P.S.
If my reply will not help, feel free to contact Pushwoosh support(http://www.pushwoosh.com/contact-us/). They will investigate your case more closely. But do not forget to send them messageid of delayed message(you can find it on notifications page)
It seems to depend on speed, sometimes a PHP call directly to APNS comes up right away other times it can take upto 15 seconds sometimes longer i would put this down to communication link with the handset and Apple Servers.
We are currently using a Drupal module for sending push notifications and they're delivered almost instantly. (2-5 secs). I don't know which one, but if you're interested I'll ask my colleague...