Я использую flutter_local_notifications для отображения уведомлений. На iPhone уведомления не отображаются, когда приложение находится в фоновом режиме. Но когда я снова открываю приложение, уведомления отображаются.
Я сделал все следующее:
AppDelegate.swift
import Flutter
import UIKit
import flutter_local_notifications
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// This is required to make any communication available in the action isolate.
FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
GeneratedPluginRegistrant.register(with: registry)
}
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as
UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Я использую flutter_local_notifications для отображения уведомлений. На iPhone уведомления не отображаются, когда приложение находится в фоновом режиме. Но когда я снова открываю приложение, уведомления отображаются. Я сделал все следующее: AppDelegate.swift[code]import Flutter import UIKit import flutter_local_notifications
// This is required to make any communication available in the action isolate. FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in GeneratedPluginRegistrant.register(with: registry) }
if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate } GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } [/code] Затем в моем классе службы уведомлений: [code]Future _setupIOSHeadsUp() async { await _firebaseMessaging.setForegroundNotificationPresentationOptions( sound: true, badge: true, ); }
Future showBigTextNotification({ required String title, required String body, String? payload, }) async { // Set up BigTextStyleInformation final bigTextStyleInformation = BigTextStyleInformation( body, // Big text content contentTitle: title, // Title for expanded view ); final notificationDetails = NotificationDetails( android: AndroidNotificationDetails( notificationChannel.id, notificationChannel.name, channelDescription: notificationChannel.description, importance: notificationChannel.importance, priority: Priority.high, styleInformation: bigTextStyleInformation, ), iOS: const DarwinNotificationDetails( presentAlert: true, presentSound: true, presentBadge: true, ), );
return _flutterLocalNotifications.show( Random().nextInt(100), title, body, notificationDetails, payload: payload, ); } [/code] Установка следующего в моей полезной нагрузке немного помогла. Теперь я могу получать уведомления, когда приложение работает в фоновом режиме. [code]apns: { payload: { aps: { "content-available": 1, }, }, }, [/code] Когда приложение iOS закрывается, уведомление по-прежнему не приходит.