首页 > 解决方案 > 当应用程序在 iOS 的前台时如何处理 Flutter FCM 推送通知?

问题描述

我在前台应用程序时使用本地通知,在 iOS 上当应用程序在前台时仍然无法收到通知,但在 Android 上它可以完美运行。

问题是当应用程序在 iOS 的前台时如何处理推送通知?

这是我的 AppDelegate.swift :

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {override func application(
      _ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

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

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
          options: authOptions,
          completionHandler: {_, _ in })
      } else {
        let settings: UIUserNotificationSettings =
        UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
      }

      application.registerForRemoteNotifications()

      FirebaseApp.configure()
      GeneratedPluginRegistrant.register(with: self)
      return super.application(application, didFinishLaunchingWithOptions: launchOptions)


    }
}

标签: iosswiftflutterpush-notificationfirebase-cloud-messaging

解决方案


我假设您正在使用该flutter_local_notifications插件进行本地通知和firebase_messaging推送通知。截至目前,这两个插件不能一起工作。这记录在第一个插件的自述文件中,并且正在对两个插件进行跟踪。您只需要等待firebase_messaging合并的拉取请求即可。

有关详细信息,请参阅此问题。


推荐阅读