Push notification problems with Back4App and APN Authentication Key - ios

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.

Related

Amazon SNS with Firebase iOS

I have integrated AWS SNS with Firebase to send Push Notifications to iOS and Android.
Everything works fine for Android, but iOS is giving me headaches. On my development device (iPhone SE), running in development mode, the notifications are always received. But when the app is installed via App Store (production), the notifications never show up, on any device. Also, after trying to send a push, the SNS Endpoint gets disabled, and for the next attempts to send it, i get the error Endpoint Disabled. I have already checked the certificates and everything seems ok.
App iOS is configured at firebase with the APNS Auth Key (.p8)
Notifications sent via Firebase Message Test are delivered, what makes me think that the problem is not with apple certificates.
The delivery status log says
{ ... error: NotRegistered }
Finally figured out the solution.
I did not know that, after updating the certificates and keys in the app store developer, I had to build a new version of the app for applying these updates.
So, I reviewed all the info related to the certificates and the push notifications. When I was sure that everything was correctly configured, I build the IPA and uploaded it for Test Flight.
Now its working as it should =)

iOS: Debugging Release/Distribution PUSH Notifications

I know I have done this successfully in the past.
I have an app with different dev streams. The app is currently in the App Store, and I am trying to track down an issue related to PUSH notifications that seems to be plaguing that version only. So, I am trying to debug Production/Release PUSH notifications. I know I have done this in the past, but it has been a while, and I have forgotten the exact set of settings that allowed this to work.
App setup is as follows:
App is tied in to Azure Notification Hub.
Notification Hub has a Production APNS certificate.
Currently, PUSH notifications succeed when the app is deployed to a device either by:
Downloading from the App Store, or
Building in Release mode with a Distribution Provisioning Profile
The problem is with a particular KIND of PUSH notification, and specifically how the app responds to it (so, it's not the PUSH notification that is the problem, but I need to be able to debug incoming PUSH notifications).
I think I remember the following to enable debugging Distribution PUSH notifications:
You have to build in Release mode.
You have to build with a Development Provisioning Profile.
But something is going wrong. No matter what combination of settings I choose, I am either unable to debug my app (and then the PUSH notifications works), or I am able to debug my app (and then the PUSH notifications fail). Has something changed in Xcode, or am I making some other mistake? Like I said before, I am positive that I have been able to get this working in the past. How can I get it working now?

Push notifications works fine in development, but device not getting notification in production

Ok, so I have an app that is in the app store. In development everything works fine I get all of the notifications that I send. I should mention that we are using Firebase for analyics and push notifications as we have a iOS and Android version of the app. Firebase account has both the correct development and correct production apns cert, the app's capabilities are set correctly to include push notifications and remote notifications in the background.
In the organizer window the entitlement for apns-environement is set to production whenever uploading to the app store or when exporting the app. Whenever the app is first installed and ran the alert to allow push notifications is shown. So my apns certs have to be configured correctly.
I am a working on contract for this company, just started 3 months ago, I would hate for these people to look at me in a bad light but I really don't know where the issue is. I am also using Xcode's automatic code signing option, with the correct provisioning profile and developer account signed in the Xcode on this mac.
Just went through this and I do not know if you solved this,
I turned push off and deleted the certs from apple dev center and created them all over again and this made everything work as it should.
I also had this line of code set to,
FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.sandbox)
I will change it to .prod when I push to the app store.

Can I send Push Notifications to Other Devices with APNS Dev iOS certificate?

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.

APNS Push notifications are not working if app is installing from iTunes and working if app is running from Xcode

i have used app with ios8.0 SDK and created explicit app id which is enabled push notifications for development environment
I have create provision profile for explicit app id and added profile to Xcode and run the app , then device token is generating, by using NWpusher i have tested notifications. notifications are working fire.
If we build the app and created ipa and installing that ipa on same device, generating different device token, and by using that device token in NWpusher app notifications are not working
Here i have used only developer environment for notifications
You have to repeat the exact same procedure that you undertook for the development certificate and testing in Xcode, once again only now for the production environment.
Getting push notifications to work can be a real pain, thus it is important to take a structured approach. Your issue is actually quite common, people tend to think that once they got push running in dev mode, it'll work in production mode immediately. This is not the case.
I recommend you to go through Ray Wenderlich's Tutorial on Push and take it step by step. They are demonstrating the case with a dev certificate as well, but the in the end they state the following (and this part is very often overread, they should point it out more clearly):
When you are ready to release your app, repeat this process for the
production certificate. The steps are the same.
You need to generate certificate and environment for distribution to work

Resources