使用Firebase和APNs Auth Key进行生产推送通知 [英] Production Push Notifications using Firebase with APNs Auth Key

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

问题描述

在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身份验证密钥,因此被列为非活动文件.

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帐户的证书,标识符和&个人资料,我已确保我的APNs身份验证密钥存在于左侧的密钥部分.我还在我的应用程序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密钥,Prod和Dev样式的证书.那可能有所作为.我发现 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 Auth Key进行生产推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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