Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit 90259dc

Browse files
author
Benjamin Scholtysik (Reimold)
authored
Merge pull request #76 from bitstadium/feature/changes-for-4.1.0
Feature/changes for 4.1.0
2 parents 759ee13 + 0b2b3f2 commit 90259dc

File tree

8 files changed

+74
-12
lines changed

8 files changed

+74
-12
lines changed

Classes/CrashReporting/BITCrashManager.m

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ - (instancetype)initWithAppIdentifier:(NSString *)appIdentifier hockeyAppClient:
166166
_crashesDir = bit_settingsDir();
167167
_settingsFile = [_crashesDir stringByAppendingPathComponent:BITHOCKEY_CRASH_SETTINGS];
168168
_analyzerInProgressFile = [_crashesDir stringByAppendingPathComponent:BITHOCKEY_CRASH_ANALYZER];
169-
170-
if ([_fileManager fileExistsAtPath:_analyzerInProgressFile]) {
171-
NSError *theError = nil;
172-
[_fileManager removeItemAtPath:_analyzerInProgressFile error:&theError];
173-
}
169+
174170
}
175171
return self;
176172
}
@@ -280,7 +276,7 @@ - (void)cleanCrashReports {
280276
}
281277
}
282278

283-
- (void)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename {
279+
- (BOOL)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename {
284280
NSString *attachmentFilename = [filename stringByAppendingString:@".data"];
285281
NSMutableData *data = [[NSMutableData alloc] init];
286282
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
@@ -289,7 +285,7 @@ - (void)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSStri
289285

290286
[archiver finishEncoding];
291287

292-
[data writeToFile:attachmentFilename atomically:YES];
288+
return [data writeToFile:attachmentFilename atomically:YES];
293289
}
294290

295291
- (void)persistUserProvidedMetaData:(BITCrashMetaData *)userProvidedMetaData {
@@ -460,6 +456,8 @@ - (void)generateTestCrash {
460456
* @param filename the crash reports temp filename
461457
*/
462458
- (void)storeMetaDataForCrashReportFilename:(NSString *)filename {
459+
BITHockeyLogVerbose(@"Storing meta data for crash report with filename %@", filename);
460+
463461
NSError *error = NULL;
464462
NSMutableDictionary *metaDict = [NSMutableDictionary dictionaryWithCapacity:4];
465463
NSString *applicationLog = @"";
@@ -476,20 +474,32 @@ - (void)storeMetaDataForCrashReportFilename:(NSString *)filename {
476474
metaDict[kBITCrashMetaApplicationLog] = applicationLog;
477475

478476
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(attachmentForCrashManager:)]) {
477+
BITHockeyLogVerbose(@"Processing attachment for crash report with filename %@", filename);
478+
479479
BITHockeyAttachment *attachment = [self.delegate attachmentForCrashManager:self];
480480

481481
if (attachment) {
482-
[self persistAttachment:attachment withFilename:[_crashesDir stringByAppendingPathComponent: filename]];
482+
BOOL success = [self persistAttachment:attachment withFilename:[_crashesDir stringByAppendingPathComponent: filename]];
483+
if (!success) {
484+
BITHockeyLogError(@"Persisting the crash attachment failed");
485+
} else {
486+
BITHockeyLogVerbose(@"Crash attachment successfully persisted.");
487+
}
488+
} else {
489+
BITHockeyLogVerbose(@"Crash attachment was nil");
483490
}
484491
}
485492

486493
NSData *plist = [NSPropertyListSerialization dataFromPropertyList:(id)metaDict
487494
format:NSPropertyListBinaryFormat_v1_0
488495
errorDescription:&errorString];
489496
if (plist) {
490-
[plist writeToFile:[_crashesDir stringByAppendingPathComponent: [filename stringByAppendingPathExtension:@"meta"]] atomically:YES];
497+
BOOL success = [plist writeToFile:[_crashesDir stringByAppendingPathComponent: [filename stringByAppendingPathExtension:@"meta"]] atomically:YES];
498+
if (!success) {
499+
BITHockeyLogError(@"Writing crash meta data failed.");
500+
}
491501
} else {
492-
BITHockeyLogError(@"ERROR: Writing crash meta data failed. %@", error);
502+
BITHockeyLogError(@"Serializing crash meta dict failed. %@", error);
493503
}
494504
}
495505

@@ -534,12 +544,15 @@ - (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput withUserProvidedMeta
534544

535545
// Called to handle a pending crash report.
536546
- (void)handleCrashReport {
547+
BITHockeyLogVerbose(@"Handling crash report");
548+
537549
NSError *error = NULL;
538550

539551
// check if the next call ran successfully the last time
540552
if (![_fileManager fileExistsAtPath:_analyzerInProgressFile]) {
541553
// mark the start of the routine
542554
[_fileManager createFileAtPath:_analyzerInProgressFile contents:nil attributes:nil];
555+
BITHockeyLogVerbose(@"AnalyzerInProgress file created");
543556

544557
[self saveSettings];
545558

Classes/CrashReporting/BITCrashManagerPrivate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
- (void)cleanCrashReports;
5151
- (NSString *)extractAppUUIDs:(BITPLCrashReport *)report;
5252

53-
- (void)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename;
53+
- (BOOL)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename;
5454

5555
- (BITHockeyAttachment *)attachmentForCrashReport:(NSString *)filename;
5656

Classes/Telemetry/BITEventData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
@property (nonatomic, copy, readonly) NSString *envelopeTypeName;
66
@property (nonatomic, copy, readonly) NSString *dataTypeName;
7+
@property (nonatomic, strong) NSDictionary *measurements;
78

89
@end

Classes/Telemetry/BITEventData.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ @implementation BITEventData
55
@synthesize envelopeTypeName = _envelopeTypeName;
66
@synthesize dataTypeName = _dataTypeName;
77
@synthesize version = _version;
8+
@synthesize properties = _properties;
9+
@synthesize measurements = _measurements;
810

911
/// Initializes a new instance of the class.
1012
- (instancetype)init {
1113
if (self = [super init]) {
1214
_envelopeTypeName = @"Microsoft.ApplicationInsights.Event";
1315
_dataTypeName = @"EventData";
1416
_version = @2;
17+
_properties = [NSDictionary new];
18+
_measurements = [NSDictionary new];
1519
}
1620
return self;
1721
}
@@ -25,6 +29,13 @@ - (NSDictionary *)serializeToDictionary {
2529
if (self.name != nil) {
2630
[dict setObject:self.name forKey:@"name"];
2731
}
32+
if (self.properties !=nil) {
33+
[dict setObject:self.properties forKey:@"properties"];
34+
}
35+
if (self.measurements) {
36+
[dict setObject:self.measurements forKey:@"measurements"];
37+
}
38+
2839
return dict;
2940
}
3041

@@ -36,6 +47,8 @@ - (instancetype)initWithCoder:(NSCoder *)coder {
3647
_envelopeTypeName = [coder decodeObjectForKey:@"self.envelopeTypeName"];
3748
_dataTypeName = [coder decodeObjectForKey:@"self.dataTypeName"];
3849
_version = [coder decodeObjectForKey:@"self.version"];
50+
_properties = [coder decodeObjectForKey:@"self.properties"];
51+
_measurements = [coder decodeObjectForKey:@"self.measurements"];
3952
}
4053
return self;
4154
}
@@ -45,6 +58,8 @@ - (void)encodeWithCoder:(NSCoder *)coder {
4558
[coder encodeObject:self.envelopeTypeName forKey:@"self.envelopeTypeName"];
4659
[coder encodeObject:self.dataTypeName forKey:@"self.dataTypeName"];
4760
[coder encodeObject:self.version forKey:@"self.version"];
61+
[coder encodeObject:self.properties forKey:@"self.properties"];
62+
[coder encodeObject:self.measurements forKey:@"self.measurements"];
4863
}
4964

5065

Classes/Telemetry/BITMetricsManager.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ NS_ASSUME_NONNULL_BEGIN
3636
*
3737
* @param eventName The event's name as a string.
3838
*/
39-
- (void)trackEventWithName:(NSString *)eventName;
39+
- (void)trackEventWithName:(nonnull NSString *)eventName;
40+
41+
/**
42+
* This method allows to track an event that happened in your app.
43+
* Remember to choose meaningful event names to have the best experience when diagnosing your app
44+
* in the web portal.
45+
*
46+
* @param eventName the name of the event, which should be tracked.
47+
* @param properties key value pairs with additional info about the event.
48+
* @param measurements key value pairs, which contain custom metrics.
49+
*/
50+
- (void)trackEventWithName:(nonnull NSString *)eventName properties:(nullable NSDictionary<NSString *, NSString *> *)properties measurements:(nullable NSDictionary<NSString *, NSNumber *> *)measurements;
4051

4152
@end
4253

Classes/Telemetry/BITMetricsManager.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,25 @@ - (void)trackEventWithName:(NSString *)eventName {
199199
});
200200
}
201201

202+
- (void)trackEventWithName:(nonnull NSString *)eventName properties:(nullable NSDictionary<NSString *, NSString *> *)properties measurements:(nullable NSDictionary<NSString *, NSNumber *> *)measurements {
203+
if (!eventName) { return; }
204+
if (self.disabled) {
205+
BITHockeyLogDebug(@"INFO: BITMetricsManager is disabled, therefore this tracking call was ignored.");
206+
return;
207+
}
208+
209+
__weak typeof(self) weakSelf = self;
210+
dispatch_async(self.metricsEventQueue, ^{
211+
typeof(self) strongSelf = weakSelf;
212+
BITEventData *eventData = [BITEventData new];
213+
[eventData setName:eventName];
214+
[eventData setProperties:properties];
215+
[eventData setMeasurements:measurements];
216+
[strongSelf trackDataItem:eventData];
217+
});
218+
}
219+
220+
202221
#pragma mark Track DataItem
203222

204223
- (void)trackDataItem:(BITTelemetryData *)dataItem {

Classes/Telemetry/BITTelemetryData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
1111

1212
@property (nonatomic, copy) NSNumber *version;
1313
@property (nonatomic, copy) NSString *name;
14+
@property (nonatomic, strong) NSDictionary *properties;
1415

1516
@end
1617

Classes/Telemetry/BITTelemetryData.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ - (instancetype)initWithCoder:(NSCoder *)coder {
1818
if(self) {
1919
_version = [coder decodeObjectForKey:@"self.version"];
2020
_name = [coder decodeObjectForKey:@"self.name"];
21+
_properties = [coder decodeObjectForKey:@"self.properties"];
2122
}
2223
return self;
2324
}
@@ -26,6 +27,7 @@ - (void)encodeWithCoder:(NSCoder *)coder {
2627
[super encodeWithCoder:coder];
2728
[coder encodeObject:self.version forKey:@"self.version"];
2829
[coder encodeObject:self.name forKey:@"self.name"];
30+
[coder encodeObject:self.properties forKey:@"self.properties"];
2931
}
3032

3133
@end

0 commit comments

Comments
 (0)