0

Objective: I am trying to detect when the app shuts down. The applicationWillTerminate is not being called after iOS kills my app.


Question:

applicationWillTerminate is not being called after app is woken app and then subsequently terminated by iOS (it has normally 10 seconds of time) in background by a location event (e.g. entering beacon region aka UIApplicationLaunchOptionsLocationKey). Why is that?

Sequence of events:

  • app is not running
  • beacon is turned on
  • app is woken up by iOS
  • after a while (10 seconds usually) app stops running
  • however applicationWillTermiante method is not being called.
mm24
  • 9,280
  • 12
  • 75
  • 170
  • applicationWillTerminate is called when your app will be closed not when it will be opened. – ekscrypto Nov 10 '15 at 16:32
  • You may want to read https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html?hl=ar#//apple_ref/occ/intfm/UIApplicationDelegate/applicationWillTerminate: as it clearly indicates "This method lets your app know that it is about to be terminated and purged from memory entirely." If your app stays in background watching a location, its probably not being purged. – ekscrypto Nov 10 '15 at 16:34
  • I have just added a better explanation, I expressed myself badly. – mm24 Nov 10 '15 at 16:34
  • Are there any other events that are fired which you could use? say `applicationDidEnterBackground:` ? – ekscrypto Nov 10 '15 at 16:38
  • Sorry, it looks like the app is already started in background mode so that will probably not fire either. What is it that you are trying to achieve exactly? Usually an app that gets woken up for a location performs a task and shut down, unless you use `[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; }];` or something similar iOS will kill your app within that timeframe. – ekscrypto Nov 10 '15 at 16:41
  • I am logging for all of those and they do occur, the one that does not occur is applicationWillTerminate – mm24 Nov 10 '15 at 16:41
  • I am trying to detect when the app shuts down. The applicationWillTerminate is not being called after iOS kills my app. – mm24 Nov 10 '15 at 16:42

0 Answers0