Firebase通知不适用于iOS 11

我正在开发一个使用Firebase推送通知的应用。 它工作得很好,直到我尝试在iOS 11中。使用与iPhone 11的通知不会到达。 这是我的代码:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^) (UIBackgroundFetchResult))completionHandler { //Manage notification } - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{ //Manage notification } 

这两种方法都没有被调用。

谢谢您的帮助!

这是Firebase的一个问题。 这似乎是与他们的最新更新,而不是iOS 11有关。他们正在为它的修复工作。

与此同时,如果您向podfile添加pod 'FirebaseInstanceID', '2.0.0' ,则会修复它。

你可以在这里阅读更多: https : //github.com/firebase/quickstart-ios/issues/327#issuecomment-332655731

你需要实现UNUserNotificationCenterDelegate

  extension AppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler(.alert) } } 

并将其设置为didFinishLaunchingWithOptions UNUserNotificationCenter对象

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { UNUserNotificationCenter.current().delegate = self return true } 

在你的项目能力中检查这个。 这对我有帮助) 在这里输入图像说明

你可以试试这个吗?

  Messaging.messaging().delegate = self Messaging.messaging().shouldEstablishDirectChannel = true