I like to know when to use sandbox APNS (gateway.sandbox.push.apple.com) and when to use production APNS (gateway.push.apple.com) to send push notification.
Currently we are using production APNS for
app store version, and
testflight version
of the app and sandbox APNS for the local (debug) version. Is this correct?
The problem is that, although we receive push notification correctly for App Store version, we do not receive push notification for testflight and local versions.
We are using same production certificate for all the versions. Is this correct?
SandBox for apps signed with iOS Development Certificate (Debug default)
Production for apps signed with iOS Distribution Certificate (Release default, including testFlight)
Note that testFlight builds are exactly same with the AppStore builds if you don't have complete separate uploads with different version or build numbers.
The recommended approach: Send your request first to the production APNS, and when that fails, send it to the sandbox APNS. And always do that, without exception.
The reason: In practice, 99.9% of all your push notifications will be handled correctly by the production APNS. There is the 0.09% that are sent by developers, which will be handled a bit slower (one rejection followed by one success) and the 0.01% that should succeed with the production APNS but for some reason don't (instead of failing once, you try twice and fail twice).
The big advantage is that it just works. You don't have to configure your server where to send push notifications, and you don't have to configure the client to tell the server where to send push notifications. You just send the push and it works.
Related
I'm using ParseServer with Back4App for an Android and iOS App. I implemented a Cloud Function on the server to send push notifications through Parse and it works for the Android app without any issues (for both debug and production apks).
With the iOS Version I am currently running into the following problem:
I created an APN Authentication Key that I uploaded to Back4App. In the process I indicated that this key is for a debug app, and sending push notifications via the Cloud Function to my iOS debug device works like a charm, no matter what device triggers the Cloud Function. This was sufficient for development.
I need to be able to get push notifications to both device types to troubleshoot together with my TestFlight testers in an open test I recently started.
For all TestFlight test devices, push notifications are not getting delivered - which is not surprising, given that the APN Key was uploaded to Back4App for debug apps only.
I thus reuploaded the APN Key and indicated that it is a production app, and now sending push notifications to the TestFlight testers works, but sending push notifications to my iOS debug test device does not.
I tried getting around this by changing the build scheme in Xcode from Debug to Release - but with a release version on my iOS debug device, the push notifications are still not being delivered to said device. I can see in my Parse Dashboard that they are being sent, but they are not getting delivered.
I am using a Notification Service Extension and set the Build Mode to Release there as well, but to no effect.
Changing the APN Authentication Key on Back4App back to Debug only allows me to receive push notifications again on my debug device.
I tried changing the APN Authentication Key (for either debug and production, since I cannot select both on Back4App) before force quitting the app, restarting it to get a new APN token saved to the ParseServer, and then sending the test notifications, also to no avail. I tried this for both my debug device and a TestFlight device, and it is always either my debug device (who gets the app straight from Xcode) or the TestFlight devices that are able to receive push notifications, never both.
I did not get around to trying it with APN Certificates for which I read that there are two distinct certificates for Production and Debug apps. While this option would be possible with Back4App, one big question remains - how do you implement push notifications both for debug and production apps in iOS with only one APN Authentication Key? And more specifically, how do you do that on Back4App?
Or are there any other ways around this issue besides the old APN Certificates? Since APN Authentication Keys are made out to be the future I'd rather implement it with that instead of the older APN Certificates.
Any help is appreciated, thanks in advance!
I found a workaround and what caused the issue:
Using APN Authentication Keys for push notifications is easier to implement and more convenient since keys don't expire, can be used across multiple apps and do not require the generation of independent development and production certificates.
But: An APN Authentication Key can only be used for EITHER development push notifications OR production push notifications (which is apparently intended by Apple).
No matter whether build settings are set to Release or Debug, a tethered physical device that gets any build straight from Xcode will always have the APN environment flag set to development - even manually setting the APN environment flag to production before building does not have an effect, it seems to be reset at build time and defaults to development. This means that my debug test device (physically connected to Xcode) can only receive development pushes, which explained my described issues.
When archiving a build and uploading it to TestFlight, the APN environment flag is automatically set to production; all TestFlight testers thus only receive production push notifications.
What I am doing to work around this is that I registered my debug test device as a TestFlight tester so that I can download my latest build from there and take advantage of production pushes. I registered this particular test device as its own group so that I can test builds only with that device that I do not want to immediately roll out to all other TestFlight users in my second (true) group of testers.
Does that mean I always need to archive any new builds and push it to my test device via TestFlight to try something new?
No, only for things that require push notifications. For everything else I still get the latest build straight from Xcode because all locally stored data (like a logged-in Parse User or Installation data) persists on my device, no matter whether I install a new version from Xcode directly or through TestFlight automated updates.
That way I can work as usual and only have to take the additional TestFlight step for any push notification-related features.
I am using onesignal plugin for push notifications in my android and ios app so I want to test push notifications first on development side and then I will upload it on ios app store. Or is there any best practice for implementation of onesignal push notification first for testing and then distribution.
Personal opinion, you do not need separate profiles/certificates for development and production anymore in case of APNs. Recently apple has made some changes. Now you only need one '.p8' push notification certificate from your 'developer.apple.com' account. You give this .p8 file to your backend team.
Xcode will automatically manage your production and development on your side.
This is what you have to do to make it work:
For the backend:
In your app delegate, inside the function where you get APNs token from apple. This APNs token will either be development or production. How does apple decide, which one to give? Well when you export an IPA/App locally, or upload it on test flight or on App store, Xcode will automatically give you production push notification APNs. When you install IPA/App locally using xcode to a phone connected to xcode or on simulator, Xcode will automatically give you development/staing push notification APNs token inside that function. And at that point you just have to send that token to your backend.
How will backend check if the user's token they are getting is production or development?
Using your URL, if it is staging, it will consider it as development APNs token.
If it is production URL, it will consider it as production APNs token.
What you have to make sure?
Make sure the Base URL is set to production if you are uploading app to test flight.
Make sure the Base URL is set to development if you are running app locally on simulator or your phone connected to your xcode.
I have a Development APNs iOS Certificate for my new app, and from my server I am successfully sending push notifications and receiving them on own iPhone, using the device token. I have a partner in this app development, and I create an .ipa file of the app and give it to him for testing. This is called ad-hoc development. It has worked for us thus far.
From my server it looks like I am successfully sending out the push notification to his device as well as mine, using HIS device token of course (but using the same Dev APNs Cert), but he never receives the notifications. I still continue to receive my notifications. I also have registered his device in my dev center. He does not have a developer account.
So after reading up a little I am thinking that maybe with this APNs Dev certificate it is impossible to send notifications to third party devices, like my partner's device in this case. I was thinking perhaps I need to create a DISTRIBUTION certificate. Is this true? Or should the notifications work for many devices just using the APNs Dev certificate?
Thanks
Pushes go out over two environments - development and production and they are not interchangeable - i.e. if you send out a push to the Apple development server intended for a release build app it won't work and vice versa.
Apps installed and run via Xcode are debug builds and you need to send the push via the dev server, an app built for distribution is a prod build and thus the pushes need to go to the prod server.
As you are probably aware the url for the two servers is different.
Needless to say the server needs to be signed with both the prod and dev push certificates for the server to be able to send pushes on both environment.
BTW the two environments do not behave the same in terms of delivery speed etc. But this is only really noticeable for silent pushes, where bizarrely the dev environment is better than the prod one.
I am trying to testflight my app, but when I use notifications I get an error because I have a development APN instead of a production APN. My problem is uploading it to parse. First I created a development SSL Certificate, then I went back and did a Production SSL Certificate, but I am having trouble uploading the Production Certificate because It's not an APN, rather a Apple Push Services. I also created a Distribution Provisioning (ad hoc).
Apples Push Notification service is a bit strange:
On the client side:
If you build your client with Xcode you usually build a "Debug" version of your app. In that case the registerForRemoteNotification method will create a sandbox device token for you.
If you build a "Release" version of your app the same method create a production device token for you.
On the server side:
If you have a sandbox device token you can only send a push notification to that device if you use Apples sandbox Push Notification service with your sandbox SSL certificate.
If you have a production device token then you have to use Apples production push notification service with your production SSL certificate to send a push notification to that device.
The tricky part is:
if you only have a device token you will not know if it is a production device token or a sandbox device token.
if you want to use release and debug clients against the same server, that server has to use the sandbox and the production service at the same time. And you need a mechanism to decide when to use which service.
BTW: there is a nice tutorial by Ray Wenderlich which also contains a useful PHP script for easy testing.
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
I have a problem with push notifications in development\distribution (app that talk with production server).
We have the same certificate in test and in productions servers.
When I run my app on device that talk with the test DB (I save device token by email) I'm getting notification, but when the app talk with the production server, I never get notification...
the certificate file is same on both servers
I signing the app in the same way
What can be the problem?
Use the APNs Production iOS type certificate on your production server. If you use the certificate with the same name but with the type "APNs Development iOS" it will not send push notifications.