InvalidApnsCredential while certificates are valid - ios

I'm trying to send a message to my push notification test app. It's been working in proof of concept several weeks ago on the same application but not anymore.
I get a failure: InvalidApnsCredential and Firebase tell us : "A message targeted to an iOS device could not be sent because the required APNs SSL certificate was not uploaded or has expired. Check the validity of your development and production certificates"
But when I check in my firebase console, it tells me that dev and prod certificate will be valid for 9 more months.
What else could be causing this message?

In case if others are also facing the issue here are few tips:
Whenever you are stuck with notification issues try sending a push via the GUI console that firebase provide to send notifications
If your live app at Appstore is not receiving push notification but is receiving notification only when running via Xcode then you have not uploaded the production certificate to the firebase console
If you have uploaded both production and development certificates and still notifications are not received then download the latest certificates and upload them again to the firebase console

Adding Team id in Firebase worked for me.
Firebase console -> General -> select your app -> Add TEAM ID
You can find team ID in Apple developer portal :
https://developer.apple.com/account/#/membership

This might pain you to hear, but it seems that the Firebase Cloud Messaging system doesn't like dashes in the bundleID. I had something alongs of my.app.bundle-y and I was receiving InvalidAPNSCredential message on postman... I eventually tried changing my bundle id to my.app.bundle when all else failed, and notifications started coming through.
This is pretty severe change, and only really reasonable if the app is not yet deployed.
If all else fails and you have a dash in your bundle id, then maybe give this a go.

In the case of uploading a .p8 file (APNs auth key), adding proper Key ID worked for me.
When you download the .p8 file from Apple. The filename will be in format AuthKey_XXXXXXXXXX.p8. The 10 digit(marked XXXXXXXXXX after the AuthKey_) is the Key ID you need to add.please refer to the image

I had this issue and was struggling to find a solution even when my APNs token were up to date and etc. I was testing on android before IOS and on the POST method to https://iid.googleapis.com/iid i left "application": com.android name instead of IOS bundle ID. just a stupid error on my side.

in my case I was uploading .p8 key with wrong key id duoble check your "APNs Authentication Key" and make sure u have the right file with the right Key ID
and team ID

The Xcode "Bundle Identifier" must match the one configured in Firebase.
In Firebase:
Project Settings > Your Apps > Apple Apps
In Xcode:
Your project > Targets > General tab > Bundle Identifier

In my case, The Apn .p8 file had been deleted from the Firebase console (and I don't know why! :| )
I had it before and just upload it and the problem was solved.
but if you don't have it, you can create a new one from the
Apple developer account -> Certificates -> Keys -> Add new key and check
Apple Push Notifications service (APNs) from the services, then download it and upload in
Firebase -> App setting -> Cloud Messaging -> Apple app configuration -> APNs Authentication Key

Related

Missing Push Notification Entitlement, even with aps-environment entitlement set. iOS and Testflight

Good morning!
I am working on getting my app to receive push notifications from Firebase cloud messaging. when I add my build to testflight, I get a warning email with the error code: ITMS-90078: Missing Push Notification Entitlement, I am allowing xcode to manage my profile, which has the aps-environment entitlement and the capability for push notifications, and a development signing certificate, as you can see in this screenshot from xcode:
Luckily, this is just a warning, so I can still push this build to my testflight testers, but they do not receive push notifications. I can confirm that firebase cloud messaging is generating the device messaging token, and it is storing in my firebase database just fine, so I assume this is not the issue.
I have also confirmed that I have a Production Apple Push notification SSL cert assigned to this bundle ID, as shown here:
After I took this screenshot, I also tried adding a development SSL cert, but the problem persists.
I have found a number of other posts on apple dev forums and here on Stack exchange, but most are fron over 4 years ago and no longer appear relevant. Example: Missing Push Notification Entitlement warning
What am I missing? Thank you for your time and help in advance!
UPDATE
I have now also attempted the to fix this by using a provisioning profile I set up, rather than allowing xcode to manage it for me. It is an "App Store Distribution" Profile.
Same issue, getting the same email error, and any installed applications do not receive push notifications. Any suggestions? Thanks!
After a multi - hour debug session with a friend of mine that is better versed in Apple processes than I am, we managed to figure out the issue. Everything was set up correctly... all my certs were in line, all of the profiles and Bundle IDs matched, everything looked good. The issue was for some reason, xcode was displaying all of my certs from appstoreconnect and developer.apple.com, but it was not including a local entitlements file with the binary that ultimately got uploaded to app store connect, which drew the error, and ultimately prevented push notifications from working. The fix was simple... just click "+ capability" next to "all" in signing and capabilities, search for and add push notifications, and bingo! This adds the proper entitlements to my binary, which then look for the certs in app store connect. This now uploads without the error message and push notifications on any installs from this new build starting working immediately. I hope this helps someone, someday! Apple, please make this more straightforward, or don't let xcode lie about its certs!

Update new APNS certificate to GCM

Generated new certificates in Apple Developer Centre.
It's weird i couldn't upload that certificates to GCM and also i couldn't see UPDATE button developer website.
It shows error {{ controller.errorMessage }}
How do I do that? Here's a screenshot of the Google Developer
You would have to import your GCM project to the Firebase Console (there won't be any changes, see my answer here) and update the certs from there.
While already importing, I would strongly advise toigrate your app(s) to start using FCM.
Same issue I was facing and able to solve !
Background : In my scenario we have an iOS App in the store and all our push notification configured through Google GCM (We were not using FCM). But we had situation where our APNS certificate is just about to get expired and we don't want to make any iOS Release(We had around 4k DAU on the current version)
Once certificate was expired any Notification we sent was throwing InvalidApnsCredentialfrom GCM.
Here is how to get out of this.
Configure you Firebase project. (Make sure you're logged into right Google account - the one you configured for setting up your GCM)
Goto : https://firebase.google.com > GET STARTED
Choose Import Google Project
You must see now all the GCM Project as below - If your logged in with correct account.
Choose the project.
Now your Firebase project is ready. It should look like below.
To Update new certificate.
Choose Setting gear at Overview.
Choose Project Settings
Now choose Cloud Messaging Tab & now you APNs Certificate section is visible.
If Certificate already expired - you must see RED flagged cell with UPLOAD & DELETE options. Upload new APNs certificate using * UPLOAD*.
You got better way to do it, please share your thoughts ! Cheers !

The APNs certificate provided does not match the current environment

It's my first time to update one app in app store after implementing the Firebase push notifications in the project. I'm trying to upload the "Production Certificate" in Firebase Console, but it gives me this:
The APNs certificate provided does not match the current environment
I want to make sure that after updating the app users will receive notifications.
Any link with tutorial to update one app in appstore is welcome.
The mistake I was making was that I was exporting the "private key" part of the certificate in Keychain Access instead of the "certificate" part. As soon as I re exported the .p12 using the correct item - it worked.
Please refer to the answer given here
The other possibility is:
You are confusing the development certificate with Production one in the certificate list of Key Chain Access.
Try to "Export" from the correct one.
This is what brought me here :)

Mismatched Bundle ID (Sandbox) in OneSignal

I'm trying to send PN to my iOS App.
I followed the standard steps, i.e.:
create new app and upload the development and distribution(sandbox) certificates
put the App id in my project: OneSignal.initWithLaunchOptions(launchOptions, appId:"myAppID")
create new template
send a message
When I sent the PN I got "send message successfully" green message, but after a while I got a warning when I clicked on it I directed to App Settings page and the warning is:
and I didn't receive any PN!!
I checked my bundle ID in my project and it's 100% matched to the uploaded certificates.
Anyone faced like this problem when trying to use OneSignal for PN?
Please help.
Thanks.
This problem happens when your application is built with a Provisioning Profile for a Bundle ID that does not match the Bundle ID of the push certificate you uploaded to OneSignal.
It is possible that you have created several builds of your application, some with the correct bundle id and some with an incorrect one. As a result you may have subscribed devices in OneSignal that are linked to different bundle ids.
If you are able to receive notifications with the latest build of your application then you can probably ignore this error. If all of the iOS notifications you send show up as "Invalid", then you must either upload a new push certificate with the correct bundle id, or build your app with a provisioning profile that matches your push certificate's bundle id.
I got this warning on a few of my failed messages that I triggered from Zapier. I verified my Bundle ID and they are exactly the same, and I was getting other notifications just fine. As #gdeglin said I'm going to ignore this warning for now, as it doesn't seem to point an issue at this point of time. If you find any other answer to this please share, I'm sure others are facing similar issues as well.

iOS: Production push notifications, Invalid token from APNS server

My app is now available in the app store, so I've downloaded it to my device. The push notifications were working fine during development. I am using JavaPNS to send out the notifications, and I have switch it to point to Apple's production servers.
However, I'm now getting an Invalid Token error back from the APNS servers.
I have the Archive scheme set to "Release", and I have Release set to use this distribution profile:
Inside that provisioning file, you can see that I have the environment set correctly:
Yet I still get the error. When I look in my database, I think the device token the app is returning to me is the same as the development one, so that could be the problem. But I don't know why it would be returning that, given that the app is signed correctly. This is a device I also used for testing, could that be a problem? Any other ideas about what's happening here?
Thanks!
EDIT: I'm not storing a token in my code, Eran's answer suggests that the only other possibilities are an old token in my database, or the app not being signed by a production profile. I'm cleared my database, so I know it's not the former, and as for the latter, I don't see how that could be the case, since I only have one distribution profile, and as I've shown above, it has the "aps-environment" key set correctly. XCode wouldn't even let me use a development profile for app store submission, would it? A few other possibilities:
Is it possible that something being wrong with key I'm sending with my notifications could cause "Invalid Token"? If so, can I regenerate this key for my existing profiles?
Isn't there another provisioning profile contained in the AppID for the purposes of push notifications? Could a problem with that cause the invalid token error?
I re-downloaded the push production certificate and exported it from the keychain as .p12. This seems to have solved the problem. It seems strange though that a bad private key was giving me the "Invalid Token" error.
The device token for production is different than the development one, so if you send a development token to production APNS servers (or vica versa), that's the cause of the problem.
It's possible you didn't remove the development device token from your server when you switched to production.
Or if you are getting the development token from your production app, then either the app is returning a locally stored device token (which you may have stored on your device during development) instead of asking Apple to get a new one, or (if you do ask Apple for a current token and still get the development token) your app is not signed with the production provisioning profile.
MyApp is an iOS app that sends and receives Push Notifications MyApp-to-MyApp using APN token IDs fetched from a database that is kept updated by each MyApp at logon. The Push Notifications are sent by MyApp using the NWPusher framework API.
As long as the project was run in Developer (Debug) mode, sent and received Push Notifications worked perfectly. But, in Production mode, sending Push Notifications would not work.
I went back and completely recreated my AppID, SSL certificates, provisions, etc., but to no avail. Next I used the NWPusher MacOS Pusher app to experiment with sending Push Notifications to MyApp. I configured Pusher to send a Push Notification (to the tokenID of an Ad Hoc distribution of MyApp) with MyApp’s Production SSL certificate, and got the following message in the Pusher log: "Notification error: APN invalid token".
I next noticed that Pusher had a checkbox option “Should use sandbox environment” checked. I unchecked the option and tried it again. This time the Push Notification was sent and then received by the target phone without any errors. This led me to take another look at the NWPusher.connect call:
Swift:
let pusher:NWPusher? = try? NWPusher.connect(withPKCS12Data: pkcs12! as Data, password:APNS_Certificate_Password,environment:NWEnvironment(rawValue:1)!)
which has an environment argument NWEnvironment enum with possible values 0=none, 1=sandbox, 2=production, 3=auto.
Changing rawValue:1 (develop sandbox) to rawValue:2 (production) fixed the problem: Production Push Notifications now work without errors.
xCode 8.0
I had "invalid token" error the after installing of xCode 8.0.
The issue was found here: Project Navigator -> select project (topmost item) -> select project name in Targets menu -> choose Capabilities in top menu -> look at PUSH Notifications section -> click "Fix issue"
Found the root cause for this issue, it is because of bad private key. To resolve this issue just generate a .p12 certificate with .pem . For creating the p12 file with .pem file please follow the below method
Under ios App Bundle IDs menu in https://developer.apple.com/account/ios/identifier/bundle
click the id of your app if in production, add a new certificate if the old one has expired.
Ensure your App Bundle ID com.myapp.mycom matches your Certificate Name com.myapp.mycom

Resources