-
Notifications
You must be signed in to change notification settings - Fork 244
/
CountlyCrashData.m
74 lines (63 loc) · 2.87 KB
/
CountlyCrashData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// CrashData.m
#import "CountlyCrashData.h"
#import "CountlyCommon.h"
@implementation CountlyCrashData
- (instancetype)initWithStackTrace:(NSString *)stackTrace name:(NSString *)name description:(NSString *)description crashSegmentation:(NSDictionary<NSString *, id> *)crashSegmentation breadcrumbs:(NSArray<NSString *> *)breadcrumbs crashMetrics:(NSDictionary<NSString *, id> *)crashMetrics fatal:(BOOL)fatal {
self = [super init];
if (self) {
_stackTrace = [stackTrace copy] ?: @"";
_name = [name copy] ?: @"";
_crashDescription = [description copy] ?: @"";
_crashSegmentation = [crashSegmentation mutableCopy] ?: @{};
_breadcrumbs = [breadcrumbs mutableCopy] ?: @[];
_crashMetrics = [crashMetrics mutableCopy] ?: @{};
_fatal = fatal;
_checksums = [NSMutableArray arrayWithCapacity:7];
_changedFields = [NSMutableArray arrayWithCapacity:7];
[self calculateChecksums:_checksums];
}
return self;
}
- (NSString *)getBreadcrumbsAsString {
NSMutableString *breadcrumbsString = [NSMutableString string];
for (NSString *breadcrumb in self.breadcrumbs) {
[breadcrumbsString appendFormat:@"%@\n", breadcrumb];
}
return [breadcrumbsString copy];
}
- (NSDictionary<NSString *, id> *)getCrashMetricsJSON {
NSMutableDictionary<NSString *, id> *crashMetrics = [NSMutableDictionary dictionary];
for (NSString *key in self.crashMetrics) {
crashMetrics[key] = self.crashMetrics[key];
}
return [crashMetrics copy];
}
- (void)calculateChangedFields {
NSMutableArray<NSString *> *checksumsNew = [NSMutableArray arrayWithCapacity:7];
[self calculateChecksums:checksumsNew];
NSMutableArray<NSNumber *> *changedFields = [NSMutableArray arrayWithCapacity:7];
for (int i = 0; i < checksumsNew.count; i++) {
changedFields[i] = @(![self.checksums[i] isEqualToString:checksumsNew[i]]);
}
self.changedFields = [changedFields copy];
}
- (NSNumber *)getChangedFieldsAsInt {
int result = 0;
for (int i = (int)self.changedFields.count - 1; i >= 0; i--) {
if (self.changedFields[i].boolValue) {
result |= (1 << ((int)self.changedFields.count - 1 - i));
}
}
return @(result);
}
- (void)calculateChecksums:(NSMutableArray<NSString *> *)checksumArrayToSet {
[checksumArrayToSet removeAllObjects];
[checksumArrayToSet addObject:[self.name cly_SHA256]];
[checksumArrayToSet addObject:[self.crashDescription cly_SHA256]];
[checksumArrayToSet addObject:[self.stackTrace cly_SHA256]];
[checksumArrayToSet addObject:[[self.crashSegmentation description] cly_SHA256]];
[checksumArrayToSet addObject:[[self.breadcrumbs description] cly_SHA256]];
[checksumArrayToSet addObject:[[self.crashMetrics description] cly_SHA256]];
[checksumArrayToSet addObject:[(self.fatal ? @"true" : @"false") cly_SHA256]];
}
@end