当应用程序在iOS前台运行时,如何处理Flutter FCM推送通知?

时间:2020-01-31 11:32:34

标签: ios swift flutter push-notification firebase-cloud-messaging

我在前台使用应用程序时使用本地通知,在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)


    }
}

1 个答案:

答案 0 :(得分:0)

我假设您正在使用flutter_local_notifications插件发送本地通知,并使用firebase_messaging推送通知。截至目前,这两个插件无法一起使用。在第一个插件的自述文件中对此进行了记录,并且在两个插件上都正在跟踪该问题。您只需要等待firebase_messaging上的合并请求即可合并。

有关更多详细信息,请参见this issue