Firebase第8页:无效的APN证书。检查设置

时间:2018-05-11 12:21:36

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

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

  

无效的APN证书。检查设置

中的证书

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

  • https://developer.apple.com/account/ios/authkey/
  • 创建了新密钥
  • 下载了p8文件
  • https://developer.apple.com/account/#/membership/
  • 获得了团队ID
  • 在设置/云消息传递
  • 下的firebase控制台中上传了.p8文件
  • 在目标/功能/推送通知下的.xcworspace:ON
  • myproject.entitlements文件包含APS环境字符串开发。
  • 注意:在developer.apple.com中,在APP ID下,如果我点击myApp ID并向下滚动,则推送通知可配置&开发显示黄色而不是绿色。

SO上的一些人建议我应该在developer.apple.com中创建一个新的Key。我做了它,按照与上面相同的过程,同样的错误。

编辑

APN在客户端生成的令牌如下: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    

enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

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