简体   繁体   English

Flutter:应用程序终止时,flutter_local_notifications onSelectNotification 不起作用

[英]Flutter : flutter_local_notifications onSelectNotification not working when app is terninated

flutter_local_notifications is working fine when the app is in foreground or background当应用程序处于前台或后台时,flutter_local_notifications 工作正常

but when the app is terminated但是当应用程序终止时

onSelectNotification not working as expected, instead it's just open the application onSelectNotification 没有按预期工作,而是打开应用程序

static void initializeLocalNotification() async {
    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
        FlutterLocalNotificationsPlugin();
    const AndroidInitializationSettings initializationSettingsAndroid =
        AndroidInitializationSettings('ic_launcher');
    final IOSInitializationSettings initializationSettingsIOS =
        IOSInitializationSettings(
      requestSoundPermission: false,
      requestBadgePermission: false,
      requestAlertPermission: false,
    );

    final InitializationSettings initializationSettings =
        InitializationSettings(
      android: initializationSettingsAndroid,
      iOS: initializationSettingsIOS,
    );
    await flutterLocalNotificationsPlugin.initialize(initializationSettings,
        onSelectNotification: (String payload) async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      var res = await prefs.setString(kNotificationPayLoad, payload);
      // navigatorKey.currentState
      //     .push(MaterialPageRoute(builder: (_) => LoginScreen()));
      // navigatorKey.currentState.pop();
    });

    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            IOSFlutterLocalNotificationsPlugin>()
        ?.requestPermissions(
          alert: true,
          badge: true,
          sound: true,
        );
  }
var details = await NotificationService()
    .flutterLocalNotificationsPlugin
    .getNotificationAppLaunchDetails();
if (details.didNotificationLaunchApp) {
    print(details.payload);
}

Use this code in the first page it can get notification tapped payload在第一页使用此代码,它可以获得通知点击的有效负载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Android 的页面开始时立即调用 flutter_local_notifications 的 onSelectNotification 方法(在 iOS 中没有此类问题) - onSelectNotification method of flutter_local_notifications called immediately on page start in Android (in iOS no such issue) flutter_local_notifications 对我不起作用 - flutter_local_notifications not working for me Flutter:使用 FCM 在前台运行时,flutter_local_notifications 不起作用 - Flutter: flutter_local_notifications not work when running in Foreground with FCM flutter_local_notifications onNotificationReceived 方法 - Flutter - flutter_local_notifications onNotificationReceived method - Flutter 如何将flutter_local_notifications添加到我的应用程序? - How do I add flutter_local_notifications to my app? flutter_local_notifications 不适用于 ios,但适用于 android - flutter_local_notifications not working on ios, but working on android 计划通知未显示(Flutter_local_notifications) - scheduled notifications not showing (Flutter_local_notifications) 使用 flutter_local_notifications 安排通知 - Schedule notification using flutter_local_notifications flutter_local_notifications 路由全屏 - flutter_local_notifications route fullscreen Flutter 本地通知 iOS `onSelectNotification` 不工作 - Flutter Local Notification iOS `onSelectNotification` is Not Working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM