[英]How to handle Flutter FCM push notification when app in foreground for iOS?
I'm using local notification when app in foreground, on iOS still cannot get notification when app in foreground but on Android it works perfectly.我在应用程序在前台时使用本地通知,在 iOS 上当应用程序在前台时仍然无法收到通知,但在 Android 上它运行良好。
The problem is how to handle push notification when app in foreground for iOS ?问题是如何在 iOS 前台应用程序时处理推送通知?
This my AppDelegate.swift :这是我的 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)
}
}
I assume you're using the flutter_local_notifications
plugin for local notifications and firebase_messaging
for push notifications.我假设你正在使用的
flutter_local_notifications
插件本地通知和firebase_messaging
推送通知。 As of right now, these two plugins do not work together.截至目前,这两个插件不能一起工作。 This is documented in the readme of the first plugin, and the issue is being tracked on both plugins.
这记录在第一个插件的自述文件中,并且正在两个插件上跟踪该问题。 You'll just have to wait for the pull request on
firebase_messaging
to be merged.您只需要等待
firebase_messaging
上的拉取请求被合并。
See this issue for more details.有关更多详细信息,请参阅此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.