1

Is there a way to get notified (by iOS) that the system is about to shutdown? I'm particularly interested in when the battery is dead and the OS is about to shutdown as a result.

I thought UIApplicationWillTerminateNotification will do the trick but it doesn't.

Thanks.

The app is running in the foreground. I basically just need to log the timestamp (of when the battery dies) and save to a file just before the device shutdown.

A-Majeed
  • 1,410
  • 1
  • 12
  • 12
  • 1
    possible duplicate of [power on events in iphone](http://stackoverflow.com/questions/13473827/power-on-events-in-iphone) – nburk Nov 02 '14 at 13:10
  • not possible next best thing it to implement - (void)applicationWillTerminate:(UIApplication *)application method in your appDelegate – Shams Ahmed Nov 02 '14 at 13:16
  • Thanks @ShamsAhmed, the `(void)applicationWillTerminate` did the trick. – A-Majeed Nov 02 '14 at 15:22

2 Answers2

1

First, the answer unfortunately is NO.

Still you'd had to differentiate two cases:

  1. Your app is in foreground: In this case, you can at least get the battery level using [[UIDevice currentDevice] batteryLevel]. Check the docs here.
  2. Your app is in background: If your app is in the background, it will just get sent a KILL signal (as explained here), which is not the same as a notification that you can subscribe or listen to.

You could try and go for checking the battery level in the background, but this probably won't fit your case either. Background execution is only allowed in very specific cases on iOS, among them location updates, VOIP, UIBackgroundTask... none of which seems to be appropriate for you on first sight... :/

Here is an excellent read on multitasking on iOS, maybe you find something that suits your case...

Community
  • 1
  • 1
nburk
  • 22,409
  • 18
  • 87
  • 132
0

not possible next best thing it to implement - (void)applicationWillTerminate:(UIApplication *)application method in your appDelegate by Shams Ahmed

A-Majeed
  • 1,410
  • 1
  • 12
  • 12