Я использую flutter_local_notifications для отображения уведомлений. На iPhone уведомления не отображаются, когда приложение находится в фоновом режиме. Но когда я снова открываю приложение, уведомления отображаются.
Я сделал все следующее:
AppDelegate.swiftimport 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)
}
}
Затем в моем классе службы уведомлений:
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,
);
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... local-noti
Уведомления не отображаются, когда приложение находится в фоновом режиме (ios, flutter_local_notifications) ⇐ IOS
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение