APNS Push Notifications not being delivered to *some* devices - ios

I developed a web API for my mobile app use it.
This API was developed with Django, and I'm using the django-push-notifications lib to handle the push notifications.
The push notifications were working fine for all the devices, until it stopped working for few of them, which worked at some point, for no apparent reason.
I already debugged the server and I can see the messages being sent to APNS and on the correct format. Also reviewed the certificates, and all is working as it should. I'm using the production certificate sending to the appropriate server.
I'm sure that this is not a problem with certs, since some other phones receive the notifications.
Where should I start looking for the problem now?
Thanks.

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.
See this link

Are you sure that those some devices does't have a development version of app ?
Try to generate a combined p12 certificate of apn development certificate and apn production certificate , than try to call gateway.push.apple.com and gateway.sandbox.push.apple.com separately.

Related

Testing push notifications in development with APNS HTTP/2

I am trying to determine what I need to do with respect to the combination of APNS endpoint (e.g., development or production), Xcode, and Apple Push certificates in order to test push notifications while in development. I feel like I've tried every possible combination, but I must be missing something ...
Background
When using Apple's HTTP/2 APNS endpoints from my "dispatch" server, my app/device does not receive pushes, and I receive a BadDeviceToken response from Apple.
Using the exact same .p12 certificate and deviceToken with the Pusher macOS testing app (which uses legacy APNS endpoints), the pushes successfully deliver.
To complicate this further ...
When using Apple's HTTP/2 APNS endpoints from my "dispatch" server for PassKit pushes, my pass/device does receive pushes.
So ...
Point #3 tells me that my "dispatch" server must be configured properly, because pushes to the Apple Wallet pass cause a response (e.g., I can see follow-on requests to my server's endpoints from the Wallet / the pass).
That said, Apple Wallet is a "Production" app. I suspect that, because my app (from Point #1) is non-production/development, something is different.
.
Question
Has anyone been able to successfully receive -- in Xcode -- push notifications sent to Apple's api.development.push.apple.com endpoint? Can you outline the steps you performed (which certificate from developers.apple.com, etc.)? Thank you!
You should be able to send development push from server:
You need to connect to api.development.push.apple.com:443 instead of api.push.apple.com:443. You can use production certificate for both.
Sending push to production server can not work with development builds - only with a build that is exported with AppStore configuration, but you can't debug those (at least not with Xcode)
If you need to check whether the production endpoint works, you can use testflight
Set development certificate from apple developer portal.
Use either production/test server for communicating with APNS.
Edit your target scheme as follows :
This will ensure that when push notification arrives, control will itself fall in the code. It might seem confusing. But here it is how it works :
- Install app on device and stop the Run process from Xcode.
- Place a breakpoint on didReceiveRemoteNotification.
- Send a push notification to device.
- Xcode will itself start the app and control will go to the above function.

Can we send push notification to APNs from iOS device?

I want to send push notification from a iOS device to another iOS device without using backend server. Is it possible for an iOS device to act like a server and send push notification to APNs server?.
Thanks in advance.
Theoretically you can send Apple Push Notifications from a device directly to another device. All you need are the push certificate of the app, the device token of the device you are sending the notification to, and code that establishes a secure TLS connection to the APNS servers.
However, there are several practical problems that make the use of a server almost mandatory :
You need a single place where all the device tokens of all the devices that installed your app will be sent to and persisted in. The best such place would be a server. Without a server, how would device A send its device token to other devices that want to send it push notifications?
Apple require that you keep connections with the APNS server open for as long as possible and use the same connection for sending many notifications. If you open a connection to APNS server on your device, it will probably be short lived (since devices switch networks frequently, and don't stay connected to the internet all the time). Therefore, if you try to send many notifications frequently, and each time use a new connection to APNS, you will probably be banned (since Apple would treat this as DDoS attack).
If you store the push certificate in each device that installs your app (to allow it to send push notifications to other devices directly), aside from the security issue of storing the certificate in many places, you'll have to publish a new version of your app each time the push certificate expires (once a year), and push notifications would stop working for users who don't upgrade to the new version.
Try NWPusher.
It has an iOS framework for sending pushes and has an iOS demo application that sends push notifications from iOS to iOS.
You also need to consider Server costs (other than maintenance and development time if you code your own server).
By sending the push directly from the app device:
- you obtain a much better scalability (since you don't have to centralize everything on your server)
- you don't have to pay for server cost or other service's cost
You can use for iOS:
- https://github.com/noodlewerk/NWPusher Pusher
And for Android:
- Send push notification GCM by java

iOS Sending a Push Notification From an iOS App, APNS

Is there anything preventing SENDING a push notification FROM an iOS application? There are reasons for my madness. If so, are there any good examples out there? I have code that should be working and if there is no blocking reason, I will post the code.
I tried on Verizon and AT&T. Would want it over a carrier for now.
Please do not comment on why, etc.
[addition]
This would not be for a public app, testing internal only.
I don't see any reason what this wouldn't work. You'll have to include the push certificate with your application, and your users will have to download a new version of your app every time the certificate expires (which means once a year). You'll also need to send to each device all the device tokens of devices it should send notifications to.
The sending code should be the same as it would be in a server that sends push notifications, but you would have to implement it in objective C.
All in all it doesn't seem like a good idea, since you'll need a server anyway (for each device to get the device tokens of other devices), so it makes more sense that the server will do the sending.
Actually yes - there are a few things that prevent you from sending push notification from iOS.
Even if you manage to install (use in your app) certificates needed to properly connect to Apple's APNS server their policy is to start blocking clients that create many short connections.
So for public app you would need to use a "normal" way of setting up your PHP server that manages communication with APNS. Otherwise many public IP's (devices) using your credentials would lead to blocking your app APNS certificate.
If this would be just for private use then there is no reason not to give it a try.

Push Notifications are not received sometimes

I have this strange problem with iOS Push Notifications:
I configured my server to send push notifications, yet sometimes they are not delivered.
In order to get them back to work on a specific device, I have to turn OFF the Wi-Fi and switch it back ON. After that the message is received.
I'm still trying to put my finger on that issue, without luck.
More Info:
1.Server is working in sandbox mode.
2.Development certificates are in use.
3.Other notifications still works while mine won't (Facebook, Whatsapp).
In my theory, there are some differences between test APNS server, and real APNS server.
I do not think that is your problem.
Log something after send a message to APNS server
Try to take off the sandbox and set it to false.
Check your certificates.. if you have ad hoc certificate, notifications will only work when you create an IPA and install it on your device. Or if you download the app from the applestore.
Another issue can may cause your problem is the Data traffic.
If your phone does not have internet unless it connects to wifi, the device doesn't recive the push notification until it is not connected to wifi.
Hope it helps.

iOS Push Notification service batch size

We are trying to send a notification to ~500,000 iOS devices. We have currently set the batch size to 200 and are noticing that Apple refuses our connection after 300k messages or so. We suspect that Apple interprets our connection/tear-downs to be a DOS attack. What is a good batch size for us to use? Also, any tips on sending notifications for such a large number of devices?
Your push notification server must maintain a persistent connection to Apple's socket stream push server without disconnecting too often.
I recommend writing your push server using Node.js, it was designed for this stuff.
However there are a few things that can also cause Apple to disconnect your push server.
With Push Notification, there are two types of certificates - development and production.
An app signed with a development certificate will generate a development push token whereas a an app signed with a production certificate will generate a different production push token even on the same device.
Your server must make sure it does not send a development token to a production socket stream connection to Apple's push server.
Mixing the token and environment will cause Apple's push server to disconnect your push server.
How you separate your push token is something that you need to build into your server.
Hope that helps.

Resources