简体   繁体   English

Firebase推送通知不适用于iOS上的生产

[英]Firebase push notifications not working for production on iOS

I integrated Firebase Messaging SDK into my iOS project, created a push notification certificate for development and one for production, uploaded both p12 keys to Firebase and I do not receive the notifications, but just for development. 我将Firebase Messaging SDK集成到我的iOS项目中,创建了一个用于开发的推送通知证书和一个用于生产的推送通知证书,将p12密钥均上载到Firebase,但我没有收到通知,而只是为了开发。

The code for registration is good, and it is the same I used for usual APNS, which worked fine. 注册代码很好,与我通常用于APNS的代码相同,效果很好。

The same behaviour happens for 3 applications. 3个应用程序发生相同的行为。

Did someone else encounter this problem? 有人遇到过这个问题吗? Do you have any solutions or suggestions? 您有什么解决方案或建议吗?

I had the same issue. 我遇到过同样的问题。 Apparently there is an error in the Firebase documentation. 显然,Firebase文档中存在错误。 When you exporting the APN certificate for production from your keychain to the .p12 file you have to select the actual certificate, not the private key . 当您将用于生产的APN证书从钥匙串导出到.p12文件时,必须选择实际的证书, 而不是私钥

Make sure you upload to the Firebase console this .p12 file in the Cloud Messaging APN certificate settings. 确保您在Cloud Messaging APN证书设置中将此.p12文件上传到Firebase控制台。

Swift 4.0 迅捷4.0

Also make sure you're using: 另外,请确保您使用的是:

Messaging.messaging().setAPNSToken(deviceToken as Data, type: .prod)

inside: 内:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    #if DEVELOPMENT
        //Develop
        Messaging.messaging().setAPNSToken(deviceToken as Data, type: .sandbox)
    #else
        //Production
        Messaging.messaging().setAPNSToken(deviceToken as Data, type: .prod)
    #endif

}

First of all check certificate which you are exporting. 首先检查您要导出的证书。 Typical mistake is to export private key and not a service. 典型的错误是导出私钥而不是服务。 I attached a screenshot. 我附上了截图。 I hope that will save some time for you. 我希望这可以为您节省一些时间。

Correct certificate to export 正确的证书出口

For me these steps resolved the same issue on production: 对我来说,这些步骤解决了生产中的相同问题:

  1. On Apple Developer portal go to Keys - > Add key 在Apple Developer门户上,转到“密钥”->“添加密钥” 在此处输入图片说明

  2. Download your key, copy Key ID parameter 下载您的密钥,复制密钥ID参数

  3. Open Firebase Console - > Project settings -> Cloud messaging 打开Firebase控制台->项目设置->云消息传递
  4. Upload your .p8 Key which you downloaded (step 2) here: 在此处上传您下载的.p8密钥(第2步): 在此处输入图片说明
  5. On new window paste Key ID parameter and your App ID prefix as required 在新窗口上,根据需要粘贴Key ID参数和您的App ID前缀

I got it working by these steps: 我通过以下步骤使其工作:

  1. Regenerate the profiles from the Apple developer portal 从Apple开发人员门户重新生成配置文件
  2. Remove the old ones 删除旧的
  3. Update the new profiles on firebase console 在Firebase控制台上更新新的配置文件
  4. Conform AppDelegate to the UNUserNotificationCenterDelegate protocol 使AppDelegate符合UNUserNotificationCenterDelegate协议
  5. Make sure all the registration to APNS is done correctly (there are plenty of tutorials on how to do this) 确保已正确完成对APNS的所有注册(有关如何执行此操作的教程很多)
  6. Make sure you called configureFirebase at app startup 确保在应用启动时调用了configureFirebase
  7. Send a message from the firebase console 从Firebase控制台发送消息

It seems that step 4 does the difference. 看来步骤4有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM