【发布时间】: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