Including Custom Data into iOS Crash Dumps

Including custom data into iOS crash dumps

No, you cannot ad your own data into the crash reports. It is also not possible to access iOS generated crash reports automatically because of the sandbox.

So my suggestion is as follows:

  1. For logging your own data, use Cocoalumberjack. It is much faster than NSLog or other logging frameworks out there and has an option to log your messages into a file. Now when an exception occurs, or whenever else you want to, log that into a file. But if your app crashes right at a point where you add something into a log file, it most likely will be missing, since the app crashed the very same moment.

    So its rather impossible to safely catch the exact SQL statement. But the crash report should give you enough information to understand what is happening, with the addition to what you logged of being done before. E.g. you could log the search string used in the SQL way before the SQL is being executed.

    In general try not to log too much.

  2. For catching crash report you should nothing else than a solution based on the open source framework PLCrashReporter, which can safely catch crashes, also when you app is already in the app store! Exception catching is not recommended, check this article to see why!

    iTunes Connect offers you to view some crash reports too, but it takes up to 2 weeks to see some, but by far not all as e.g. pointed out by the Camera+ developers. So you better use your own solution.

    PLCrashReporter will send you standard apple formatted crash reports, ready for symbolication, so you know where the crash happens in your code, including line numbers.

    Some solutions based on PLCrashReporter are:

    • QuincyKit: Open Source client + php server, basic crash grouping, symbolication can be automated from your mac (I am the developer of this)
    • HockeyApp: Paid service, uses QuincyKit client, advanced crash grouping, symbolication fully done on the server (I am on of the developers of this)
    • Bugsense: Free service, symbolication announced as premium feature
    • AppBlade: Paid service, symbolication unknown
    • Crashlytics: Private beta, unknown features, their solution seems to be based on PLCrashReporter
  3. The proposed solutions either allow sending the data automatically on the next startup or by asking the user if he/she agrees to send.

Low Memory Warning always causing crash on iPad (1st generation)

To be sure, you should try to get the crash log from the device. The tester has to sync the device with iTunes, and then navigate to the folder where iTunes copied any crash reports. This depends on what platform you are using.

Mac OS X: ~/Library/Logs/CrashReporter/MobileDevice/<DEVICE_NAME>
Windows XP: C:\Documents and Settings\<USERNAME>\Application Data\Apple Computer\Logs\CrashReporter\MobileDevice\<DEVICE_NAME>
Windows Vista or 7: C:\Users\<USERNAME>\AppData\Roaming\Apple Computer\Logs\CrashReporter\MobileDevice\<DEVICE_NAME>

<USERNAME> is the user's login name for the computer. <DEVICE_NAME> is the name of the iPod touch or iPhone, for example, "My iPhone".

There are ways to collect the crash reports automatically, I posted an overview on the possibilities as part of another answer here: Including custom data into iOS crash dumps

In addition you can automate memory warnings when testing in the iOS simulator. Subclass UIViewController and automatically trigger memory warnings whenever the view controller appears.

Here is some example code on how to do that:

#import "BaseViewController.h"

@interface BaseViewController (Private)
- (void)simulateMemoryWarning;
@end

@implementation BaseViewController

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

#if TARGET_IPHONE_SIMULATOR
#if defined (CONFIGURATION_Debug)
// If we are running in the simulator and it's the DEBUG target
// then simulate a memory warning. Note that the DEBUG flag isn't
// defined by default. To define it add this Preprocessor Macro for
// the Debug target: DEBUG=1
[self simulateMemoryWarning];
#endif
#endif
}

- (void)simulateMemoryWarning {
#if TARGET_IPHONE_SIMULATOR
#if defined (CONFIGURATION_Debug)
SEL memoryWarningSel = @selector(_performMemoryWarning);
if ([[UIApplication sharedApplication] respondsToSelector:memoryWarningSel]) {
[[UIApplication sharedApplication] performSelector:memoryWarningSel];
} else {
NSLog(@"%@",@"Whoops UIApplication no loger responds to -_performMemoryWarning");
}
(CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);
#endif
#endif
}

@end

Now use this when subclassing your own view controller instead of subclassing from UIViewController. This code was originally posted here https://gist.github.com/956403 and adjusted to work with Xcode 4.2.1 by adding the solution from here https://stackoverflow.com/a/2785175/474794

How to read the contents of the device console on iPhone?

The console is not saved to a file on the iPhone (which is why reboots completely clear it).

I would recommend replacing your NSLogs with something that logs to the console as well as a file within the Documents directory of your app and allow provide functionality within the app to send in the file to an email.

The location of where the crash logs are kept is outside the sandbox of the application, so you can't access the crash logs directly, but sync'ing with iTunes will cause them to be uploaded to the developer's iTunes Connect account.

How can i relaunch the app after it crashed

You should rather use a library that leverages PLCrashReporter by Landon Fuller. It is much safer, creates standard crash reports, you get all threads including last exception backtrace, allows you to symbolicate them and get the line numbers of your own code. See this blog post for more details why it is safer: http://landonf.bikemonkey.org/code/objc/Reliable_Crash_Reporting.20110912.html

There are multiple frameworks and services build on top of PLCrashReporter, which I mentioned in this answer: Including custom data into iOS crash dumps

In addition you can NOT re-launch the app after it crashed (one exception is, if your app is providing voice over ip functionality). There is no code, especially Objective-C code that you should launch once your app crashed, see the linked blog post above, so you can't invoke a local notification either.



Related Topics



Leave a reply



Submit