Add ability to add a description to a crash report

This commit is contained in:
Lukas Spieß 2014-04-22 17:52:14 +02:00
parent 91698b85a3
commit d22fb02ec2
2 changed files with 21 additions and 8 deletions

View File

@ -265,7 +265,7 @@ typedef NS_ENUM(NSUInteger, BITCrashManagerUserInput) {
@return BOOl if the input is a valid option @return BOOl if the input is a valid option
@see BITCrashManagerUserInput @see BITCrashManagerUserInput
*/ */
- (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput; - (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput withCrashMetaDescription:metaDescription;
/** /**
Provides the time between startup and crash in seconds Provides the time between startup and crash in seconds

View File

@ -55,6 +55,7 @@
#define kBITCrashMetaUserID @"BITCrashMetaUserID" #define kBITCrashMetaUserID @"BITCrashMetaUserID"
#define kBITCrashMetaApplicationLog @"BITCrashMetaApplicationLog" #define kBITCrashMetaApplicationLog @"BITCrashMetaApplicationLog"
#define kBITCrashMetaAttachment @"BITCrashMetaAttachment" #define kBITCrashMetaAttachment @"BITCrashMetaAttachment"
#define kBITCrashMetaDescription @"BITCrashMetaDescription"
// internal keys // internal keys
NSString *const KBITAttachmentDictIndex = @"index"; NSString *const KBITAttachmentDictIndex = @"index";
@ -74,6 +75,7 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
NSMutableArray *_crashFiles; NSMutableArray *_crashFiles;
NSString *_crashesDir; NSString *_crashesDir;
NSString *_lastCrashFilename;
NSString *_settingsFile; NSString *_settingsFile;
NSString *_analyzerInProgressFile; NSString *_analyzerInProgressFile;
NSFileManager *_fileManager; NSFileManager *_fileManager;
@ -487,7 +489,7 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
} }
} }
- (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput { - (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput withCrashMetaDescription:(NSString *)metaDescription{
switch (userInput) { switch (userInput) {
case BITCrashManagerUserInputDontSend: case BITCrashManagerUserInputDontSend:
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) { if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) {
@ -498,6 +500,11 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
YES; YES;
case BITCrashManagerUserInputSend: case BITCrashManagerUserInputSend:
if (!metaDescription && [metaDescription length] > 0) {
NSError *error;
[metaDescription writeToFile:[NSString stringWithFormat:@"%@_description.meta", [_crashesDir stringByAppendingPathComponent: _lastCrashFilename]] atomically:YES encoding:NSUTF8StringEncoding error:&error];
BITHockeyLog(@"ERROR: Writing crash meta description failed. %@", error);
}
[self sendCrashReports]; [self sendCrashReports];
YES; YES;
@ -591,6 +598,7 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
} else { } else {
BITHockeyLog(@"ERROR: Writing crash meta data failed. %@", error); BITHockeyLog(@"ERROR: Writing crash meta data failed. %@", error);
} }
_lastCrashFilename = cacheFilename;
} }
} }
} }
@ -902,6 +910,7 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
useremail = [self stringValueFromKeychainForKey:[NSString stringWithFormat:@"%@.%@", cacheFilename, kBITCrashMetaUserEmail]] ?: @""; useremail = [self stringValueFromKeychainForKey:[NSString stringWithFormat:@"%@.%@", cacheFilename, kBITCrashMetaUserEmail]] ?: @"";
userid = [self stringValueFromKeychainForKey:[NSString stringWithFormat:@"%@.%@", cacheFilename, kBITCrashMetaUserID]] ?: @""; userid = [self stringValueFromKeychainForKey:[NSString stringWithFormat:@"%@.%@", cacheFilename, kBITCrashMetaUserID]] ?: @"";
applicationLog = [metaDict objectForKey:kBITCrashMetaApplicationLog] ?: @""; applicationLog = [metaDict objectForKey:kBITCrashMetaApplicationLog] ?: @"";
description = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@_description.meta", [_crashesDir stringByAppendingPathComponent: _lastCrashFilename]] encoding:NSUTF8StringEncoding error:&error];
BITCrashAttachment *attachment = [self attachmentForCrashReport:filename]; BITCrashAttachment *attachment = [self attachmentForCrashReport:filename];
if (attachment) { if (attachment) {
@ -914,7 +923,11 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
} }
if ([applicationLog length] > 0) { if ([applicationLog length] > 0) {
description = [NSString stringWithFormat:@"%@", applicationLog]; if ([description length] > 0) {
description = [NSString stringWithFormat:@"%@\n\nLog:\n%@", description, applicationLog];
} else {
description = [NSString stringWithFormat:@"Log:\n%@", applicationLog];
}
} }
[crashes appendFormat:@"<crash><applicationname>%s</applicationname><uuids>%@</uuids><bundleidentifier>%@</bundleidentifier><systemversion>%@</systemversion><platform>%@</platform><senderversion>%@</senderversion><version>%@</version><uuid>%@</uuid><log><![CDATA[%@]]></log><userid>%@</userid><username>%@</username><contact>%@</contact><installstring>%@</installstring><description><![CDATA[%@]]></description></crash>", [crashes appendFormat:@"<crash><applicationname>%s</applicationname><uuids>%@</uuids><bundleidentifier>%@</bundleidentifier><systemversion>%@</systemversion><platform>%@</platform><senderversion>%@</senderversion><version>%@</version><uuid>%@</uuid><log><![CDATA[%@]]></log><userid>%@</userid><username>%@</username><contact>%@</contact><installstring>%@</installstring><description><![CDATA[%@]]></description></crash>",
@ -962,13 +975,13 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (buttonIndex) { switch (buttonIndex) {
case 0: case 0:
[self handleUserInput:BITCrashManagerUserInputDontSend]; [self handleUserInput:BITCrashManagerUserInputDontSend withCrashMetaDescription:nil];
break; break;
case 1: case 1:
[self handleUserInput:BITCrashManagerUserInputSend]; [self handleUserInput:BITCrashManagerUserInputSend withCrashMetaDescription:nil];
break; break;
case 2: case 2:
[self handleUserInput:BITCrashManagerUserInputAlwaysSend]; [self handleUserInput:BITCrashManagerUserInputAlwaysSend withCrashMetaDescription:nil];
break; break;
} }
} }