当应用被杀死时,带有标题和描述的推送通知。
| iOS | Android |
|---|---|
|
|
您需要通知权限,因此请将以下内容添加到您的 ios/Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
# dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=1',
]
end
end
end
final _notificationWhenAppIsKilledPlugin = NotificationWhenAppIsKilled();
await _notificationWhenAppIsKilledPlugin.setNotificationOnKillService(
ArgsForKillNotification(
title: 'The app is killed',
description:
'You can see this notification when the app is killed'),
)
final _notificationWhenAppIsKilledPlugin = NotificationWhenAppIsKilled();
await _notificationWhenAppIsKilledPlugin
.cancelNotificationOnKillService()
)
感谢 gdelataillade,大部分代码是他的。请查看他在Medium上的文章:https://medium.com/@gdelataillade/displaying-a-notification-when-your-flutter-app-is-killed-4ef25cc3f193
检查此包和 onKill 通知仅在发布版本下有效,不在调试版本下有效。