0

I would like to perform certain cleanup tasks when the app shuts down. I use an observer like:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActiveNotif:) name:UIApplicationWillResignActiveNotification object:nil];

to get notified when the app goes to background.

The problem is that if the app crashes, there is no notification for me to do something.

I saw that testflight.com use a hook to recover crash information, I was wondering if it was possible to also detect crashes and perform some tasks.

My concern is regarding the call to:

CLLocationManager.stopMonitoringSignificantLocationChanges

not being done when app crashes, leaving users with a constant location icon on top. I know that crashes are not supposed to be frequent, but would like to clean as much as possible if I can under these circumstances.

Resh32
  • 6,500
  • 3
  • 32
  • 40
  • If your app crashes, the OS immediately terminates it - there's **no way** you can do anything after that. The solution is to fix your app so it never crashes. –  Nov 15 '12 at 10:23
  • 1
    Did you take a look at this solution? http://stackoverflow.com/questions/10885313/detect-app-crashed-during-load-last-time-it-was-run – Duyen-Hoa Nov 15 '12 at 10:40

1 Answers1

3

you could install a global exceptionHandler or even a signalHandler http://www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html

but remember: dont continue running after a crash. it is NOT safe :D

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • When an app crashes, you should **NOT** run any Objective-C code, because it is not safe! See http://landonf.bikemonkey.org/code/objc/Reliable_Crash_Reporting.20110912.html – Kerni Nov 15 '12 at 13:45
  • I said its not safe, but it works.. and entering a modal runloop doesnt hurt. you have to design it to be reentrant-safe and without taking care, it is not. – Daij-Djan Nov 15 '12 at 16:11