Production Push Notifications using Firebase with APNs Auth Key

与世无争的帅哥 提交于 2019-12-10 07:09:27

问题


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)
}

回答1:


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.



来源:https://stackoverflow.com/questions/44446527/production-push-notifications-using-firebase-with-apns-auth-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!