blob: 54a1216c0460214a0075760a32375acd0c7b7fe7 (
plain)
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
|
#import "MGLMetricsManager_Private.h"
#import "MGLNetworkConfiguration_Private.h"
#if TARGET_OS_IOS
#import "MGLMapboxEvents.h"
#endif
NSString* MGLStringFromMetricType(MGLMetricType metricType) {
return [@[kMGLDownloadPerformanceEvent] objectAtIndex:metricType];
}
@interface MGLMetricsManager() <MGLNetworkConfigurationMetricsDelegate>
@end
@implementation MGLMetricsManager
+ (instancetype)sharedManager
{
static dispatch_once_t once;
static id sharedConfiguration;
dispatch_once(&once, ^{
sharedConfiguration = [[self alloc] init];
[MGLNetworkConfiguration sharedManager].metricsDelegate = sharedConfiguration;
});
return sharedConfiguration;
}
- (void)handleMetricsEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
if ([self.delegate shouldHandleMetric:metricType]) {
[self.delegate metricsManager:self didCollectMetric:metricType withAttributes:attributes];
}
}
#if TARGET_OS_IOS
- (void)pushMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
NSString *eventName;
switch (metricType) {
case MGLMetricTypePerformance:
eventName = kMGLDownloadPerformanceEvent;
break;
default:
break;
}
[MGLMapboxEvents pushEvent:eventName withAttributes:attributes];
}
#endif
- (void)networkConfiguration:(MGLNetworkConfiguration *)networkConfiguration didGenerateMetricEvent:(NSDictionary *)metricEvent {
[self handleMetricsEvent:MGLMetricTypePerformance withAttributes:metricEvent];
}
@end
|