gpt4 book ai didi

flutter : flutter_local_notifications onSelectNotification not working when app is terninated

转载 作者:行者123 更新时间:2023-12-04 14:44:10 30 4
gpt4 key购买 nike

当应用程序处于前台或后台时,flutter_local_notifications 工作正常
但是当应用程序终止时
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);
}
在第一页中使用此代码,它可以获得通知挖掘有效载荷

关于 flutter : flutter_local_notifications onSelectNotification not working when app is terninated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66837143/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com