Skip to content

Commit

Permalink
Fix duplicate notification sound on foreground
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 committed Mar 6, 2025
1 parent 7754924 commit 248cf1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ part 'fcm_remote_message_providers.g.dart';
/// If the application is in the foreground, the Firebase SDK will block displaying any FCM notification
/// for android/iOS no matter what Notification Channel has been set. We can however still handle incoming notifications
/// via the onMessage stream and display a custom local notification using flutter_local_notifications.
/// Note: FCM can handle foreground for iOS by using `setForegroundNotificationPresentationOptions` but if you
/// want to use custom notification instead then avoid using it (or disable alert) as done in [_setupIOSHeadsUp].
/// Note: FCM can handle foreground for iOS by using `setForegroundNotificationPresentationOptions`
/// but if you intend to use a custom notification, avoid using it to prevent duplicate heads-up notifications.
///
/// Using custom notification display for iOS in foreground is necessary to be able to
/// handle notification interaction using `onDidReceiveNotificationResponse` from flutter_local_notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ class NotificationService {
}

/// Update the iOS foreground notification presentation options to allow heads up notifications.
/// Disable alert if you're using flutterLocalNotification to handle foreground notifications
/// instead of FCM, otherwise, you'll get duplicated heads up notification.
/// Avoid this if you're using flutterLocalNotification to handle foreground notifications
/// instead of FCM, otherwise, you'll receive duplicate heads-up notifications.
Future<void> _setupIOSHeadsUp() async {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
/* await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
sound: true,
badge: true,
);
); */
}

Future<AuthorizationStatus> _requestPermissions() async {
Expand Down

0 comments on commit 248cf1e

Please sign in to comment.