Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 9, 2013, 04:46 PM   #1
straber
macrumors member
 
Join Date: Jul 2012
handling app crash

I was recently playing with an app and it suddenly crashed (it's happened to all of us). But, when I re-launched the app I got an alert that said, "Our app quit unexpectedly, would you like to send an error report so we can fix this?" This made me curious for two reasons:

1.) How was their app able to detect that it had crashed?

2.) What information did their app send that would help them fix the crash?


Thank you for any help!

Last edited by straber; Mar 17, 2013 at 10:05 PM.
straber is offline   0 Reply With Quote
Old Feb 9, 2013, 07:27 PM   #2
xArtx
macrumors 6502a
 
Join Date: Mar 2012
It might not be so sinister.
It could write a key when it exits and detect the
Value is incorrect at startup.

2) values of working variables, state, etc. all the usual.
xArtx is offline   0 Reply With Quote
Old Feb 10, 2013, 01:57 PM   #3
Ides
macrumors member
 
Join Date: Mar 2012
I don't know much about this, but arent all app crashes recorded by the system and written to a log file somewhere? You can see this log file when you plug your device into Xcode.
Ides is offline   1 Reply With Quote
Old Feb 10, 2013, 05:19 PM   #4
straber
Thread Starter
macrumors member
 
Join Date: Jul 2012
Quote:
Originally Posted by Ides View Post
I don't know much about this, but arent all app crashes recorded by the system and written to a log file somewhere? You can see this log file when you plug your device into Xcode.
It's true, you can get crash logs through Xcode, but that's not what I'm looking for. I'm trying to figure out how an app can detect that it's crashed all on its own after it's been released to customers.
straber is offline   0 Reply With Quote
Old Feb 10, 2013, 08:51 PM   #5
xArtx
macrumors 6502a
 
Join Date: Mar 2012
Do this at startup:
Code:
	cleanexit = [[NSUserDefaults standardUserDefaults] integerForKey:@"exit"];
    if (cleanexit == 0) {// do something like send crash log}
 	cleanexit = 0;
    [[NSUserDefaults standardUserDefaults] setInteger:launchkeyval forKey:@"exit"];
    [[NSUserDefaults standardUserDefaults] synchronize];
and this on exit:

Code:
 	cleanexit = 1;
    [[NSUserDefaults standardUserDefaults] setInteger:launchkeyval forKey:@"exit"];
    [[NSUserDefaults standardUserDefaults] synchronize];
Now if the value read for cleanexit at startup is zero it is either the program's first launch,
or it crashed the last time it was run.
xArtx is offline   1 Reply With Quote
Old Feb 10, 2013, 08:59 PM   #6
straber
Thread Starter
macrumors member
 
Join Date: Jul 2012
Quote:
Originally Posted by xArtx View Post
Do this at startup:
Code:
	cleanexit = [[NSUserDefaults standardUserDefaults] integerForKey:@"exit"];
    if (cleanexit == 0) {// do something like send crash log}
 	cleanexit = 0;
    [[NSUserDefaults standardUserDefaults] setInteger:launchkeyval forKey:@"exit"];
    [[NSUserDefaults standardUserDefaults] synchronize];
and this on exit:

Code:
 	cleanexit = 1;
    [[NSUserDefaults standardUserDefaults] setInteger:launchkeyval forKey:@"exit"];
    [[NSUserDefaults standardUserDefaults] synchronize];
Now if the value read for cleanexit at startup is zero it is either the program's first launch,
or it crashed the last time it was run.
This seems like the best way to do it to me. Thanks! Now my only question is, when my app becomes active, what information does it have access to about the previous crash that I can have it send me?
straber is offline   0 Reply With Quote
Old Feb 10, 2013, 10:46 PM   #7
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by straber View Post
This seems like the best way to do it to me. Thanks! Now my only question is, when my app becomes active, what information does it have access to about the previous crash that I can have it send me?
You could keep track of when large tasks are in progress... maybe if it takes 5 seconds to parse a large XML file, for example, you could know which file it was parsing when it crashed.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 10, 2013, 11:38 PM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Rather than rolling your own, you might want to consider incorporating something like TestFlight SDK, which has crash reporting in realtime.
__________________
dejo is offline   0 Reply With Quote
Old Mar 17, 2013, 10:04 PM   #9
straber
Thread Starter
macrumors member
 
Join Date: Jul 2012
I ended up writing this function in my app delegate.

Code:
void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
    // Internal error reporting
}
and added this line of code inside appDidFinishLaunching.

Code:
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
This will call the above function anytime an exception is not handled, and you have access to the exception. From that function you can log the exception however you like, store it to a key in the defaults seems easiest, then check if there is any data for that key when the app launches.
straber is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPad: App crash coolesterman Jailbreaks and iOS Hacks 2 Apr 15, 2014 12:03 PM
Mavericks Mail.App handling Gmail Dorv OS X Mavericks (10.9) 4 Oct 23, 2013 03:29 PM
Manual Handling iPhone and iPad training App lysyblic iPhone and iPod touch Apps 0 May 2, 2013 11:43 AM
Advise on Photo App data handling blackrabbit iPhone/iPad Programming 1 Jan 23, 2013 10:22 AM
Crash to safe mode after downloading an app from the app store TL24 iPhone Tips, Help and Troubleshooting 0 Jun 26, 2012 08:31 AM

Forum Jump

All times are GMT -5. The time now is 02:37 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC