Giter Site home page Giter Site logo

dtkdt100 / notification_when_app_is_killed Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 4.0 77 KB

Push notification when app is killed

Home Page: https://pub.dev/packages/notification_when_app_is_killed

License: BSD 3-Clause "New" or "Revised" License

Kotlin 21.76% Java 2.38% Dart 49.90% Swift 16.73% Objective-C 0.13% Ruby 9.10%

notification_when_app_is_killed's Introduction

Notification When App Is Killed

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

Credit to gdelataillade

RPReplay_Final1695065849.mp4
screen-20230919-161310.1.mp4

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

notification_when_app_is_killed's People

Contributors

dtkdt100 avatar

Stargazers

 avatar  avatar  avatar MahdiBagjani avatar 永恒瞬间 avatar  avatar Ido Sharon avatar Gautier de Lataillade avatar

Watchers

 avatar

notification_when_app_is_killed's Issues

Example on Android device

Hi.
First of all thanks for developing this package.
I run the example code on android device but nothing happening.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.