Skip to content

Commit 36dd9aa

Browse files
authored
Merge pull request #23 from AhmedLSayed9/enhance/avoid_duplicate_notification_sound_on_foreground
Fix duplicate notification sound on foreground
2 parents 7754924 + 248cf1e commit 36dd9aa

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/core/infrastructure/notification/fcm_remote_message_providers.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ part 'fcm_remote_message_providers.g.dart';
2121
/// If the application is in the foreground, the Firebase SDK will block displaying any FCM notification
2222
/// for android/iOS no matter what Notification Channel has been set. We can however still handle incoming notifications
2323
/// via the onMessage stream and display a custom local notification using flutter_local_notifications.
24-
/// Note: FCM can handle foreground for iOS by using `setForegroundNotificationPresentationOptions` but if you
25-
/// want to use custom notification instead then avoid using it (or disable alert) as done in [_setupIOSHeadsUp].
24+
/// Note: FCM can handle foreground for iOS by using `setForegroundNotificationPresentationOptions`
25+
/// but if you intend to use a custom notification, avoid using it to prevent duplicate heads-up notifications.
2626
///
2727
/// Using custom notification display for iOS in foreground is necessary to be able to
2828
/// handle notification interaction using `onDidReceiveNotificationResponse` from flutter_local_notifications

lib/core/infrastructure/notification/notification_service.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ class NotificationService {
110110
}
111111

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

122123
Future<AuthorizationStatus> _requestPermissions() async {

0 commit comments

Comments
 (0)