简体   繁体   中英

Method called on crash iOS app

The problem is i want to send something to keychain right before my application will be terminated (and yes, i mean terminated - no in background).

I am pretty sure that AppDelegate method:

- (void)applicationWillTerminate:(UIApplication *)application

works before on similar situations. But now, this method is never called.

I'm using Xcode 5 and develop for iOS 7.0

I'm not sure that applicationWillTerminate: is trigged when crashing.

I call during didFinishLaunchingWithOptions: :

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

Then, in your appDelegate, add :

void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
    // Internal error reporting
}

Maybe you could save something to keychain from this method.

For Swift 4

Right this code in didFinishLaunchingWithOptions() :

NSSetUncaughtExceptionHandler { exception in
            print("Error Handling: ", exception)
            print("Error Handling callStackSymbols: ", exception.callStackSymbols)
        }

And any time when your app will crash then this block will be called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM