notification_when_app_is_killed 0.0.4 copy "notification_when_app_is_killed: ^0.0.4" to clipboard
notification_when_app_is_killed: ^0.0.4 copied to clipboard

Push notification with title and description when the app is killed.

Notification When App Is Killed #

Push notification with title and description when the app is killed.

Credit to gdelataillade

https://github.com/dtkdt100/notification_when_app_is_killed/assets/63166757/cdb1763c-c294-40a1-8283-7775b9d831dd

https://github.com/dtkdt100/notification_when_app_is_killed/assets/63166757/e74d8bb6-e26b-49c2-a94b-dd3af7880911

Getting Started #

iOS #

  1. You will need notification permission so add this to your 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
  1. Add this to your `ios/AppDelegate.swift'
.
.
import UserNotifications
import notification_when_app_is_killed

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
   override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {

    if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
    }

   .
   .
   .
  }

  override func applicationWillTerminate(_ application: UIApplication) {
    let notificationWhenAppIsKilledInstance = NotificationWhenAppIsKilledPlugin.instance
    notificationWhenAppIsKilledInstance.applicationWillTerminate();
  }
}

see example AppDelegate.swift

How to use #

setNotificationOnKillService: #

final _notificationWhenAppIsKilledPlugin = NotificationWhenAppIsKilled();

ArgsForIos argsForIos = ArgsForIos(
  interruptionLevel: InterruptionLevel.critical,
  useDefaultSound: true,
);
await _notificationWhenAppIsKilledPlugin.setNotificationOnKillService(
  ArgsForKillNotification(
      title: 'The app is killed',
      description:
          'You can see this notification when the app is killed',
      argsForIos: argsForIos),
)

cancelNotificationOnKill: #

final _notificationWhenAppIsKilledPlugin = NotificationWhenAppIsKilled();

await _notificationWhenAppIsKilledPlugin
              .cancelNotificationOnKillService()
)

Credit #

Thanks to gdelataillade, most of this code is his. Checkout his article in Medium: https://medium.com/@gdelataillade/displaying-a-notification-when-your-flutter-app-is-killed-4ef25cc3f193

Notes #

Checking this package and the onKill notification will only work under release and not under dabug

9
likes
140
pub points
62%
popularity

Publisher

unverified uploader

Push notification with title and description when the app is killed.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, permission_handler, plugin_platform_interface

More

Packages that depend on notification_when_app_is_killed