【问题标题】:How to handle Flutter FCM push notification when app in foreground for iOS?当应用程序在 iOS 的前台时如何处理 Flutter FCM 推送通知?
【发布时间】:2020-05-17 01:50:13
【问题描述】:

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


    }
}

【问题讨论】:

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


    【解决方案1】:

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

    更多详情请见this issue

    【讨论】:

    • 我使用了flutter_local_notifications:^1.1.5+1和firebase_messaging:^6.0.9
    猜你喜欢
    • 2021-04-19
    • 2017-06-26
    • 2019-01-11
    • 1970-01-01
    • 2023-03-11
    • 2018-07-31
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多