无法从 Firebase 控制台接收 IOS 条通知

Unable to receive IOS notifications from Firebase Console

我坚持向用户推送通知。在 Xcode,我收到了 Firebase 发送的所有通知。但是,当推送到 App Store 时,我不再收到它们。

它在 firebase 上说发送了 X 数量但为零 received/open。

这是我的应用委托:

    Did Finish Launching:

    //Firebase Integration
    FirebaseApp.configure()
    FirebaseConfiguration.shared.setLoggerLevel(.min)

    //Enabling push notifications
    registerForPushNotifications()

    //Handle Notification
           
    if #available(iOS 10.0, *) {
      // For iOS 10 display notification (sent via APNS)
      UNUserNotificationCenter.current().delegate = self

      let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
      UNUserNotificationCenter.current().requestAuthorization(
        options: authOptions,
        completionHandler: { _, _ in }
      )
    } else {
      let settings: UIUserNotificationSettings =
        UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
      application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()
    
    Messaging.messaging().delegate = self

这是通用应用委托及其内容。

  General App Delegate:

    //Register for Push Not.
    func registerForPushNotifications() {
    UNUserNotificationCenter.current()
      .requestAuthorization(
        options: [.alert, .sound, .badge]) { [weak self] granted, _ in
        print("Permission granted: \(granted)")
        guard granted else { return }
        self?.getNotificationSettings()
      }
}
        //Get Settings
        func getNotificationSettings() {
  UNUserNotificationCenter.current().getNotificationSettings { settings in
    print("Notification settings: \(settings)")
    
    guard settings.authorizationStatus == .authorized else { return }
    DispatchQueue.main.async {
      UIApplication.shared.registerForRemoteNotifications()
    }
  }
} 

    //Get the token
    func application(
  _ application: UIApplication,
  didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
  Messaging.messaging().apnsToken = deviceToken
}

这里有一些扩展函数。不确定我是否需要它们。

extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler:
@escaping (UNNotificationPresentationOptions) -> Void
 ) {
if #available(iOS 14.0, *) {
    completionHandler([[.banner, .sound]])
} else {
    // Fallback on earlier versions
}
}

 func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
 ) {
  completionHandler()
 }
}



 extension AppDelegate: MessagingDelegate {
 func messaging(
_ messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
 ) {
let tokenDict = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
  name: Notification.Name("FCMToken"),
  object: nil,
  userInfo: tokenDict)
  }
 }

转到 firebase-> 项目设置-> 云消息传递 -> 然后向下滚动到 Apple 应用程序配置,确保您提供了 APNs 生产证书,如果没有,则生成生产证书并将其上传到那里。或者,我建议您上传 APNs 身份验证密钥而不是证书。