Firebase p8: недействительный сертификат APN.Проверьте сертификат в настройках - PullRequest
0 голосов
/ 11 мая 2018

Я успешно зарегистрировался в APN и получил идентификатор токена. Проблема в том, что когда я отправляю уведомление с консоли Firebase, я получаю сообщение об ошибке

Неверный сертификат APN. Проверьте сертификат в настройках

Это шаги, которые я выполнил, чтобы назначить сертификат .p8 APN для Firebase. Я тестирую приложение на устройстве Iphone. Что я делаю не так?

  • создал новый ключ в https://developer.apple.com/account/ios/authkey/
  • скачал файл p8
  • получил идентификатор команды от https://developer.apple.com/account/#/membership/
  • загрузил файл .p8 в консоль Firebase в разделе «Настройки / облачные сообщения»
  • в моем .xcworspace разделе Цели / Возможности / Push-уведомления: ON
  • Файл myproject.entitlements содержит строку разработки APS Environment.
  • ПРИМЕЧАНИЕ: В developer.apple.com, под идентификаторами APP, если я нажимаю на myApp id и прокручиваю вниз, Push-уведомления Configurable & Development отображаются желтым цветом, а не зеленым.

Некоторые люди из SO предложили мне создать новый ключ на developer.apple.com. Я сделал это, следуя тому же процессу, что и выше, и той же ошибке.

РЕДАКТИРОВАТЬ

Токен, сгенерированный 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 голосов
/ 01 июня 2018

Я думаю, это может быть связано с тем, что вы пропустили этап создания профиля Provisioning.Ссылка здесь: https://firebase.google.com/docs/cloud-messaging/ios/certs?authuser=0

...