使用 Firebase 和 APNs 身份验证密钥的生产推送通知 [英] Production Push Notifications using Firebase with APNs Auth Key

查看:114
本文介绍了使用 Firebase 和 APNs 身份验证密钥的生产推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 TestFlight 上测试我的应用程序时,我注意到我没有收到推送通知.

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

我已确认,当从 Xcode 加载构建时,我可以接收从云功能和 Firebase 控制台发起的通知.

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

我参考了其他类似的问题,但没有一个反映我正在处理的确切问题.在 Firebase 中配置远程通知时,我使用的是 APNs 身份验证密钥,我还包含了用于开发和生产的 .p12 文件.但是,.p12 文件变灰并列为非活动,因为 APNs Auth Key 已设置.

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.

在我的 Apple Developer 帐户中的 Certificates, Identifiers & 下配置文件,我已确保我的 APNs 身份验证密钥存在于左侧 密钥 部分.我还在我的 App Id & 中设置了开发者和生产 SSL 证书.验证它们被列为已启用".我还确认我有一个活动"的 iOS 分发配置文件.

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".

这是一个难以调试的问题,因为 Xcode 构建可以工作,而 TestFlight 构建却不能.我知道这个问题涉及生产环境和开发环境,但我不确定如何解决这个问题.

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.

此方法在 Xcode 构建和所有相关的 UserNotifications 中被调用 &正在调用 Messaging 委托方法.我正在运行 iOS 10.3 &在我的 info.plist 中将 FirebaseAppDelegateProxyEnabled 设置为 NO.

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

推荐答案

对我来说解决方法是停止使用 MessagingAPNSTokenType.sandbox 或 .prod,而只使用:

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)

并设置 Config 以依赖于 Xcode 中的构建方案.现在它似乎不适用于生产.在 Firebase 上,我现在使用的是 APNS Key,而不是旧的样式生产和开发证书.这可能有所作为.我看到 Firebase 文档 现在也说:

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:

如果令牌类型设置为 UNKNOWN Firebase Messaging 将隐式尝试从配置中找出实际的令牌类型轮廓.除非你真的需要指定类型,否则你应该使用APNSToken 属性.

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.

这篇关于使用 Firebase 和 APNs 身份验证密钥的生产推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆