Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Production Push Notifications using Firebase with APNs Auth Key

When testing my application on TestFlight I have noticed that I do not receive push notifications.

I have confirmed that I can receive notifications initiated from both cloud functions and the firebase console when loading builds from Xcode.

I have referenced other similar questions but none of them reflect the precise problem I am dealing with. When configuring for remote notifications in Firebase I am using an APNs Auth Key, I have also included both .p12 files for Development and Production. However, the .p12 files are greyed out and listed as inactive because the APNs Auth Key has been setup.

On my Apple Developer account under Certificates, Identifiers & Profiles, I have made sure that my APNs Auth Key exists in the left Keys section. I have also setup Developer and Production SSL Certificates in my App Id & verified that they are listed as "enabled". I have also verified that I have an iOS Distribution Provisioning Profile that is "active".

This is a difficult problem to debug because Xcode builds work yet TestFlight builds do not. I know this issue deals with production vs. development environments but I'm not sure how to fix the problem.

This method is being called in Xcode builds and all associated UserNotifications & Messaging delegate methods are being called. I am running iOS 10.3 & have FirebaseAppDelegateProxyEnabled set to NO in my info.plist.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
     Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.sandbox)
     Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.prod)
}
like image 365
Eli Whittle Avatar asked Nov 07 '22 21:11

Eli Whittle


1 Answers

The fix for me was to stop using MessagingAPNSTokenType.sandbox or .prod, and just use:

Messaging.messaging().setAPNSToken(deviceToken, type: .unknown)

In a previous app, I used:

if Config.isDebug {
    tokenType = MessagingAPNSTokenType.sandbox
} else {
    tokenType = MessagingAPNSTokenType.prod
}
Messaging.messaging().setAPNSToken(deviceToken, type: tokenType)

and set up Config to depend on the build scheme in Xcode. Now it appears not to work in prod. On Firebase, I am now using an APNS Key, as opposed to the older style Prod and Dev certificates. That may have made a difference. I see that the Firebase docs also now say:

If the token type is set to UNKNOWN Firebase Messaging will implicitly try to figure out what the actual token type is from the provisioning profile. Unless you really need to specify the type, you should use the APNSToken property instead.

like image 162
Steve Harris Avatar answered Nov 14 '22 23:11

Steve Harris