Firebase p8:无效的 APN 证书.在设置中检查证书 [英] Firebase p8: Invalid APN Certificate. Check the certificate in Settings
问题描述
我已成功注册 APN 并收到令牌 ID.问题是当我从 Firebase 控制台发送通知时,我收到错误
<块引用>无效的 APN 证书.在设置中检查证书
这是我为将 .p8 APN 证书分配给 Firebase 所遵循的步骤.我正在 Iphone 设备上测试该应用程序.我做错了什么?
- 在
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
Invalid APN Certificate. Check the certificate in Settings
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.
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.
EDIT
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
解决方案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屋!