Add property which tells after which time interval since app startup the crash happened

This is absolute time, not the sum of session times! This can be used to detect crashes on startup and defer app initialization after the crash report has been send by also using the new delegates for networking operations
This commit is contained in:
Andreas Linde 2012-07-03 17:32:14 +02:00
parent 4a10d000d0
commit 2cf10b0db0
2 changed files with 14 additions and 1 deletions

View File

@ -164,6 +164,7 @@ typedef enum CrashReportStatus {
BOOL _autoSubmitCrashReport;
BOOL _didCrashInLastSession;
NSTimeInterval _timeintervalCrashInLastSessionOccured;
NSString *_appIdentifier;
@ -224,9 +225,12 @@ typedef enum CrashReportStatus {
// if NO, the user will be asked if the crash report can be submitted (default)
@property (nonatomic, assign, getter=isAutoSubmitCrashReport) BOOL autoSubmitCrashReport;
// will return if the last session crashed, to e.g. make sure a "rate my app" alert will not show up
// will return YES if the last session crashed, to e.g. make sure a "rate my app" alert will not show up
@property (nonatomic, readonly) BOOL didCrashInLastSession;
// will return the timeinterval from startup to the crash in seconds, default is -1
@property (nonatomic, readonly) NSTimeInterval timeintervalCrashInLastSessionOccured;
// If you want to use HockeyApp instead of your own server, this is required
@property (nonatomic, retain) NSString *appIdentifier;

View File

@ -98,6 +98,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
@synthesize autoSubmitCrashReport = _autoSubmitCrashReport;
@synthesize languageStyle = _languageStyle;
@synthesize didCrashInLastSession = _didCrashInLastSession;
@synthesize timeintervalCrashInLastSessionOccured = _timeintervalCrashInLastSessionOccured;
@synthesize loggingEnabled = _loggingEnabled;
@synthesize appIdentifier = _appIdentifier;
@ -140,6 +141,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
_sendingInProgress = NO;
_languageStyle = nil;
_didCrashInLastSession = NO;
_timeintervalCrashInLastSessionOccured = -1;
_loggingEnabled = NO;
_fileManager = [[NSFileManager alloc] init];
@ -817,6 +819,13 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
NSLog(@"Could not load crash report: %@", error);
} else {
[_crashData writeToFile:[_crashesDir stringByAppendingPathComponent: cacheFilename] atomically:YES];
// get the startup timestamp from the crash report, and the file timestamp to calculate the timeinterval when the crash happened after startup
PLCrashReport *report = [[[PLCrashReport alloc] initWithData:_crashData error:&error] autorelease];
if (report.systemInfo.timestamp && report.applicationInfo.applicationStartupTimestamp) {
_timeintervalCrashInLastSessionOccured = [report.systemInfo.timestamp timeIntervalSinceDate:report.applicationInfo.applicationStartupTimestamp];
}
}
}