@@ -976,6 +976,31 @@ + (NSMutableDictionary *) addCrashOpsConstantFields:(NSDictionary *) reportJson
976976
977977 NSMutableDictionary *reportCopy = [reportJson mutableCopy ];
978978 reportCopy[@" devicePlatform" ] = @" ios" ;
979+ NSMutableDictionary *system = [reportCopy[@" system" ] mutableCopy ];
980+ if (!system) {
981+ system = [NSMutableDictionary new ];
982+ }
983+
984+ NSDictionary *appInfoDictionary = [[NSBundle mainBundle ] infoDictionary ];
985+ CODebugLog ([appInfoDictionary description ]);
986+
987+ NSString *appBuildNumberString;
988+ if (appInfoDictionary[@" CFBundleVersion" ]) {
989+ NSInteger appBuildNumber = [appInfoDictionary[@" CFBundleVersion" ] intValue ];
990+ appBuildNumberString = [NSString stringWithFormat: @" %ld " , (long ) appBuildNumber];
991+ }
992+
993+ NSString *appVersionString;
994+ if (appInfoDictionary[@" CFBundleShortVersionString" ]) {
995+ appVersionString = [appInfoDictionary[@" CFBundleShortVersionString" ] description ];
996+ }
997+
998+ [system co_setOptionalObject: NSBundle .mainBundle.bundleIdentifier forKey: @" CFBundleIdentifier" ];
999+ [system co_setOptionalObject: appVersionString forKey: @" CFBundleShortVersionString" ];
1000+ [system co_setOptionalObject: appBuildNumberString forKey: @" CFBundleVersion" ];
1001+
1002+ reportCopy[@" system" ] = system;
1003+
9791004 reportCopy[@" crashOpsSdkVersion" ] = [CrashOps sdkVersion ]; // [NSString stringWithCString:CrashOpsVersionString encoding: NSUTF8StringEncoding];
9801005 reportCopy[@" buildMode" ] = [CrashOps isRunningOnDebugMode ] ? @" DEBUG" : @" RELEASE" ;
9811006
@@ -1036,14 +1061,20 @@ -(void) onEventFileCreated:(NSString *) eventId {
10361061 NSLog (@" New event ID saved: %@ " , eventId);
10371062
10381063 NSString *eventIdFile = [[self eventsFolderPath ] stringByAppendingPathComponent: eventId];
1064+ if (eventIdFile) {
1065+ NSData *eventIdData = [appSessionId dataUsingEncoding: NSUTF8StringEncoding];
1066+ [eventIdData writeToFile: eventIdFile options: NSDataWritingAtomic error: nil ];
1067+ } else {
1068+ [CrashOpsController logInternalError: [NSString stringWithFormat: @" Failed to save session ID: %@ " , appSessionId]];
1069+ }
10391070
1040- NSData *eventIdData = [appSessionId dataUsingEncoding: NSUTF8StringEncoding];
1041- [eventIdData writeToFile: eventIdFile options: NSDataWritingAtomic error: nil ];
1042-
10431071 NSString *sessionIdFile = [[self sessionsFolderPath ] stringByAppendingPathComponent: appSessionId];
1044-
1045- NSData *sessionIdData = [eventId dataUsingEncoding: NSUTF8StringEncoding];
1046- [sessionIdData writeToFile: sessionIdFile options: NSDataWritingAtomic error: nil ];
1072+ if (sessionIdFile) {
1073+ NSData *sessionIdData = [eventId dataUsingEncoding: NSUTF8StringEncoding];
1074+ [sessionIdData writeToFile: sessionIdFile options: NSDataWritingAtomic error: nil ];
1075+ } else {
1076+ [CrashOpsController logInternalError: [NSString stringWithFormat: @" Failed to save event ID: %@ " , eventId]];
1077+ }
10471078}
10481079
10491080-(void ) handleException : (NSException *) exception {
@@ -1085,19 +1116,26 @@ - (BOOL) logError:(NSDictionary *) errorDetails {
10851116 NSString *nowString = [CrashOpsController stringFromDate: now withFormat: @" yyyy-MM-dd-HH-mm-ss-SSS_ZZZ" ];
10861117
10871118 NSString *filePath = [[self errorsFolderPath ] stringByAppendingPathComponent: [NSString stringWithFormat: @" ios_error_%@ _%@ .log" , nowString, [[NSUUID UUID ] UUIDString ]]];
1088-
1119+ if (!filePath) {
1120+ return ;
1121+ }
1122+
10891123 NSArray *breadcrumbs = [ScreenTracer tracesReportForSessionId: sessionId];
10901124
10911125 NSDictionary *jsonDictionary = @{@" errorDetails" : errorDetails,
1092- @" report" :@{@" id" : [NSNumber numberWithInteger: timestamp],
1093- @" time" : nowString},
1126+ @" report" :@{@" id" : [[NSUUID UUID ] UUIDString ],
1127+ @" timestamp" : [NSNumber numberWithInteger: timestamp],
1128+ @" time" : nowString
1129+ },
10941130 // @"details": [self generateReport: [NSException exceptionWithName:@"Error" reason:@"" userInfo:@{@"isFatal": NO}]],
10951131 @" details" : [self generateReport: nil ],
10961132 @" screenTraces" : breadcrumbs,
10971133 @" isFatal" : @NO
10981134 };
1135+
1136+ NSMutableDictionary *crashOpsDictionary = [CrashOpsController addCrashOpsConstantFields: jsonDictionary];
10991137
1100- NSData *errorData = [CrashOpsController toJsonData: jsonDictionary ];
1138+ NSData *errorData = [CrashOpsController toJsonData: crashOpsDictionary ];
11011139
11021140 NSError *error;
11031141 BOOL didSave = [errorData writeToFile: filePath options: NSDataWritingAtomic error: &error];
@@ -1362,10 +1400,14 @@ - (void) flushToDisk:(ScreenDetails *) screenDetails {
13621400 [[self coGlobalOperationQueue ] addOperationWithBlock: ^{
13631401 NSUInteger timestamp = screenDetails.timestamp ;
13641402 NSString *filePath = [[[CrashOpsController shared ] currentSessionTracesFolderPath ] stringByAppendingPathComponent: [NSString stringWithFormat: @" %lu .log" , (unsigned long ) timestamp]];
1403+ BOOL didSave = NO ;
1404+
1405+ if (filePath) {
1406+ NSData *traceData = [[CrashOpsController toJsonString: [screenDetails toDictionary ]] dataUsingEncoding: NSUTF8StringEncoding];
13651407
1366- NSData *traceData = [[CrashOpsController toJsonString: [screenDetails toDictionary ]] dataUsingEncoding: NSUTF8StringEncoding];
1408+ didSave = [traceData writeToFile: filePath options: NSDataWritingAtomic error: nil ];
1409+ }
13671410
1368- BOOL didSave = [traceData writeToFile: filePath options: NSDataWritingAtomic error: nil ];
13691411 if (!didSave) {
13701412 [CrashOpsController logInternalError: [NSString stringWithFormat: @" Failed to flush screen details to disk. Screen details: %@ " , screenDetails]];
13711413 }
0 commit comments