Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When use flutter_local_notifications with firebase message on ios 18 get push notification twice #2449

Open
Nak-2000 opened this issue Nov 11, 2024 · 0 comments

Comments

@Nak-2000
Copy link

Nak-2000 commented Nov 11, 2024

Describe the bug
since the ios18 release there's some issue with push notification twice when I use flutter local notification function inside FirebaseMessaging.onMessage.listen() function. and it's only happen to ios18 device (even after firebase has already fix the notification twice but the local notification still push twice).

Expected behavior
I would expect the notification to only push once.

Sample code to reproduce the problem

var initializationSettingsAndroid = const AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = const DarwinInitializationSettings(
defaultPresentAlert: true,
);

var initializationSettings = InitializationSettings(android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: (response) async {

print("onDidReceiveNotificationResponse:");
selectNotificationSubject.add(response.payload!);
print("onDidReceiveNotificationResponse: ${response.payload}");

});

FirebaseMessaging.onMessage.listen((RemoteMessage remoteMessage) {
var message = remoteMessage.data;
print("onMessage==>: listen $message");
appNotification = AppNotification(
id: message['id'],
type: message['type'],
title: message['title'],
content: message['content'],
referenceId: message['reference_id'],
screenDetail: message['detail_screen'],
);
_showNotification(appNotification);
});

Future _showNotification(AppNotification? appNotification) async {
try {
const AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails(
'default_channel_id',
'your_channel_name',
channelDescription: 'your_channel_description',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
);

  const NotificationDetails platformChannelSpecifics = NotificationDetails(android: androidPlatformChannelSpecifics);
  await flutterLocalNotificationsPlugin.show(
    1,
    "${appNotification!.title}",
    "${appNotification.content}",
    platformChannelSpecifics,
    payload: jsonEncode(appNotification),
  );
} on Exception catch (e) {
  log("show notification error $e");
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant