Firebase p8:无效的APN证书.在设置中检查证书 [英] Firebase p8: Invalid APN Certificate. Check the certificate in Settings

查看:255
本文介绍了Firebase p8:无效的APN证书.在设置中检查证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have successfully registered with APN and I received the token ID. The problem is that when I send a notification from Firebase console, I get error

无效的APN证书.在设置"中检查证书

Invalid APN Certificate. Check the certificate in Settings

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

This is the steps I followed in order to assign the .p8 APN certificate to Firebase. I am testing the app on an Iphone device. What am I doing wrong?

  • created new key at https://developer.apple.com/account/ios/authkey/
  • downloaded the p8 file
  • got the Team ID from https://developer.apple.com/account/#/membership/
  • uploaded the .p8 file in firebase console under Settings/cloud messaging
  • in my .xcworspace under Targets/Capabilities/Push Notifications : ON
  • myproject.entitlements file contains APS Environment String development.
  • NOTE: In developer.apple.com, under APP IDs, if I click on myApp id and scroll down, Push Notifications Configurable & Development show in yellow color and not green.

SO上的某些人建议我应该在developer.apple.com中创建一个新的Key.我做到了,遵循与上述相同的过程,并且存在相同的错误.

Some people on SO suggested I should create a new Key in developer.apple.com. I did it, followed same process as above, and same error.

编辑

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

The token generated by APNs on client side looks like: 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    

推荐答案

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

I think this may be due to you missing the step of creating a Provisioning profile. Reference here: https://firebase.google.com/docs/cloud-messaging/ios/certs?authuser=0

这篇关于Firebase p8:无效的APN证书.在设置中检查证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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