summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-03-20 15:30:36 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-03-28 15:05:27 -0700
commit9c0898acddfa739d26ce01280294f27f237ca7b5 (patch)
tree79e955d4fc6d1efbb9e4a289ed3e0998440604d1
parentf709a8f1f3788b0967a57f7b23424819ecd7d57b (diff)
downloadqtlocation-mapboxgl-9c0898acddfa739d26ce01280294f27f237ca7b5.tar.gz
[ios, macos] Update metrics manager documentation.
-rw-r--r--platform/darwin/src/MGLMetricsManager.h54
-rw-r--r--platform/darwin/src/MGLMetricsManager.m24
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration.m11
-rw-r--r--platform/ios/app/MBXAppDelegate.m4
4 files changed, 70 insertions, 23 deletions
diff --git a/platform/darwin/src/MGLMetricsManager.h b/platform/darwin/src/MGLMetricsManager.h
index 29fd5c79f8..49b3391a72 100644
--- a/platform/darwin/src/MGLMetricsManager.h
+++ b/platform/darwin/src/MGLMetricsManager.h
@@ -3,30 +3,74 @@
NS_ASSUME_NONNULL_BEGIN
+/**
+ :nodoc:
+ The metrics type used to handle metrics events.
+ */
typedef NS_ENUM(NSUInteger, MGLMetricType) {
+ /** :nodoc:
+ Metric that measures performance.
+ */
MGLMetricTypePerformance = 0,
};
FOUNDATION_EXTERN MGL_EXPORT NSString* MGLStringFromMetricType(MGLMetricType metricType);
@class MGLMetricsManager;
-@protocol MGLMetricsDelegate <NSObject>
-- (BOOL)shouldHandleMetric:(MGLMetricType)metricType;
+/**
+ :nodoc:
+ The `MGLMetricsManagerDelegate` protocol defines a set of methods that you
+ can use to receive metric events.
+ */
+@protocol MGLMetricsManagerDelegate <NSObject>
+
+/**
+ :nodoc:
+ Asks the delegate whether the metrics manager should handle metric events.
+
+ @param metricsManager The metrics manager object.
+ @param metricType The metric type event.
+ */
+- (BOOL)metricsManager:(MGLMetricsManager *)metricsManager shouldHandleMetric:(MGLMetricType)metricType;
+
+/**
+ :nodoc:
+ Asks the delegate to handle metric events.
+
+ @param metricsManager The metrics manager object.
+ @param metricType The metric type event.
+ @param attributes The metric attributes.
+ */
- (void)metricsManager:(MGLMetricsManager *)metricsManager didCollectMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes;
@end
-typedef void (^MGLEventHandler)(NSString *eventName, NSDictionary *attributes);
-
+/**
+ :nodoc:
+ The `MGLMetricsManager` object provides a single poin to collect SDK metrics
+ such as tile download latency.
+ */
MGL_EXPORT
@interface MGLMetricsManager : NSObject
+/**
+ :nodoc:
+ Returns the shared metrics manager object.
+ */
@property (class, nonatomic, readonly) MGLMetricsManager *sharedManager;
-@property (nonatomic, weak) id<MGLMetricsDelegate> delegate;
+/**
+ :nodoc:
+ The metrics manager delegate that will recieve metric events.
+ */
+@property (nonatomic, weak) id<MGLMetricsManagerDelegate> delegate;
#if TARGET_OS_IOS
+/**
+ :nodoc:
+ Sends metric events to Mapbox.
+ */
- (void)pushMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes;
#endif
diff --git a/platform/darwin/src/MGLMetricsManager.m b/platform/darwin/src/MGLMetricsManager.m
index 54a1216c04..e90a1d1d3e 100644
--- a/platform/darwin/src/MGLMetricsManager.m
+++ b/platform/darwin/src/MGLMetricsManager.m
@@ -5,7 +5,14 @@
#endif
NSString* MGLStringFromMetricType(MGLMetricType metricType) {
- return [@[kMGLDownloadPerformanceEvent] objectAtIndex:metricType];
+ NSString *eventName;
+
+ switch (metricType) {
+ case MGLMetricTypePerformance:
+ eventName = kMGLDownloadPerformanceEvent;
+ break;
+ }
+ return eventName;
}
@interface MGLMetricsManager() <MGLNetworkConfigurationMetricsDelegate>
@@ -26,27 +33,16 @@ NSString* MGLStringFromMetricType(MGLMetricType metricType) {
}
- (void)handleMetricsEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
- if ([self.delegate shouldHandleMetric:metricType]) {
+ if ([self.delegate metricsManager:self 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;
- }
+ NSString *eventName = MGLStringFromMetricType(metricType);
[MGLMapboxEvents pushEvent:eventName withAttributes:attributes];
-
}
#endif
diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m
index 0041b35c45..bac4d12ee5 100644
--- a/platform/darwin/src/MGLNetworkConfiguration.m
+++ b/platform/darwin/src/MGLNetworkConfiguration.m
@@ -14,13 +14,20 @@ NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace";
@implementation MGLNetworkConfiguration
+- (instancetype)init {
+ if (self = [super init]) {
+ self.sessionConfiguration = nil;
+ _events = [NSMutableDictionary dictionary];
+ }
+
+ return self;
+}
+
+ (instancetype)sharedManager {
static dispatch_once_t onceToken;
static MGLNetworkConfiguration *_sharedManager;
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
- _sharedManager.sessionConfiguration = nil;
- _sharedManager.events = [NSMutableDictionary dictionary];
});
return _sharedManager;
diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m
index 1216c98dd6..6abee91557 100644
--- a/platform/ios/app/MBXAppDelegate.m
+++ b/platform/ios/app/MBXAppDelegate.m
@@ -4,7 +4,7 @@
NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken";
-@interface MBXAppDelegate() <MGLMetricsDelegate>
+@interface MBXAppDelegate() <MGLMetricsManagerDelegate>
@end
@@ -52,7 +52,7 @@ NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken";
return NO;
}
-- (BOOL)shouldHandleMetric:(MGLMetricType)metricType {
+- (BOOL)metricsManager:(MGLMetricsManager *)metricsManager shouldHandleMetric:(MGLMetricType)metricType {
return YES;
}