【问题标题】:Firebase p8: Invalid APN Certificate. Check the certificate in SettingsFirebase p8:无效的 APN 证书。检查设置中的证书
【发布时间】:2018-10-21 20:49:40
【问题描述】:

我已成功注册 APN 并收到令牌 ID。问题是当我从 Firebase 控制台发送通知时,我收到错误

无效的 APN 证书。检查设置中的证书

这是我为将 .p8 APN 证书分配给 Firebase 所遵循的步骤。我正在 Iphone 设备上测试该应用程序。 我做错了什么?

  • https://developer.apple.com/account/ios/authkey/ 创建了新密钥
  • 下载了p8文件
  • https://developer.apple.com/account/#/membership/ 获得团队 ID
  • 已将 .p8 文件上传到 Firebase 控制台的“设置/云消息传递”下
  • 在我的 .xcworspace 中的 Targets/Capabilities/Push Notifications 下:ON
  • myproject.entitlements 文件包含 APS 环境字符串开发。
  • 注意: 在 developer.apple.com 中,在 APP ID 下,如果我单击 myApp id 并向下滚动,Push Notifications Configurable & Development 会显示为黄色而不是绿色。

SO 上的一些人建议我应该在 developer.apple.com 中创建一个新密钥。我做到了,遵循与上述相同的过程,同样的错误。

编辑

APNs 在客户端生成的令牌如下:cUEPUvXjRnI:APA91bGrXvRpjXiIj0jtZkefH-wZzdFzkxauwt4Z2WbZWBSOIj-Kf3a4XqTxjTSkRfaTWLQX-Apo7LAe0SPc2spXRlM8TwhI3VsHfSOHGzF_PfMb89qzLBooEJyObGFMtiNdX-6Vv8L7

import UIKit
import Firebase
import FirebaseCore
import FirebaseMessaging
import FirebaseInstanceID
import UserNotifications

 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?


   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

     FIRApp.configure()

     //firInstanceIDTokenRefresh - > called when system determines that tokens need to be refreshed
     //when firInstanceIDTokenRefresh is called, our method is called too self.tokenRefreshNotification:
     NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification(notification:)), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)

     //obtain the user’s permission to show any kind of notification
     registerForPushNotifications()
   return true

 }//end of didFinishLaunchingWithOptions


 //obtain the user’s permission to show any kind of notification
 func registerForPushNotifications() {

     // iOS 10 support
     if #available(iOS 10, *) {
        UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in
            print("Permission granted: \(granted)")

            guard granted else {return}
            self.getNotificationSettings()
        }

    }
        // iOS 9 support
    else if #available(iOS 9, *) {
        UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
        self.getNotificationSettings()
    }
        // iOS 8 support
    else if #available(iOS 8, *) {
        UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
        self.getNotificationSettings()
    }
        // iOS 7 support
    else {
        UIApplication.shared.registerForRemoteNotifications(matching: [.badge, .sound, .alert])
    }
}//end of registerForPushNotifications()



   //if user decliens permission when we request authorization to show notification
  func getNotificationSettings() {
    UNUserNotificationCenter.current().getNotificationSettings { (settings) in
        print("Notification settings: \(settings)")
         print("settings.authorizationStatus is \(settings.authorizationStatus)")
        guard settings.authorizationStatus == .authorized else {return}
        UIApplication.shared.registerForRemoteNotifications()
    }
 }



   func application(_ application: UIApplication,didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("Failed to register: \(error)")
  }


 func tokenRefreshNotification(notification: NSNotification) {
    let refereshToken = FIRInstanceID.instanceID().token()
    print("instance ID token is \(refereshToken)")

    connectToFcm()
 }


  func connectToFcm() {
    FIRMessaging.messaging().connect { (error) in
        if error != nil  {
            print("unable to connect to FCM")
        }else {
            print("connected to FCM")
        }
     }
   }

 }//end of AppDelegate    

【问题讨论】:

  • firebase 应用程序中的 bundle id 输入错误,因此无法正常工作。

标签: swift3 apple-push-notifications firebase-cloud-messaging


【解决方案1】:

我认为这可能是由于您错过了创建配置文件的步骤。参考这里:https://firebase.google.com/docs/cloud-messaging/ios/certs?authuser=0

【讨论】:

    猜你喜欢
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多