summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-03-28 17:33:59 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-03-28 17:33:59 -0700
commit10bf41709306dcf0c740ceffc0f135a16af5ae70 (patch)
tree64e7bab58374d76729661b640672759839bc0d51
parent9c0898acddfa739d26ce01280294f27f237ca7b5 (diff)
downloadqtlocation-mapboxgl-upstream/fabian-expose-events.tar.gz
[ios, macos] Add device metadata.upstream/fabian-expose-events
-rw-r--r--platform/darwin/src/MGLMetricsManager.m50
1 files changed, 48 insertions, 2 deletions
diff --git a/platform/darwin/src/MGLMetricsManager.m b/platform/darwin/src/MGLMetricsManager.m
index e90a1d1d3e..2557432fda 100644
--- a/platform/darwin/src/MGLMetricsManager.m
+++ b/platform/darwin/src/MGLMetricsManager.m
@@ -2,6 +2,9 @@
#import "MGLNetworkConfiguration_Private.h"
#if TARGET_OS_IOS
#import "MGLMapboxEvents.h"
+#import <mach-o/arch.h>
+#import <sys/utsname.h>
+#import <UIKit/UIKit.h>
#endif
NSString* MGLStringFromMetricType(MGLMetricType metricType) {
@@ -17,6 +20,8 @@ NSString* MGLStringFromMetricType(MGLMetricType metricType) {
@interface MGLMetricsManager() <MGLNetworkConfigurationMetricsDelegate>
+@property (strong, nonatomic) NSDictionary *metadata;
+
@end
@implementation MGLMetricsManager
@@ -24,10 +29,40 @@ NSString* MGLStringFromMetricType(MGLMetricType metricType) {
+ (instancetype)sharedManager
{
static dispatch_once_t once;
- static id sharedConfiguration;
+ static MGLMetricsManager *sharedConfiguration;
dispatch_once(&once, ^{
sharedConfiguration = [[self alloc] init];
[MGLNetworkConfiguration sharedManager].metricsDelegate = sharedConfiguration;
+#if TARGET_OS_IOS
+ UIDevice *currentDevice = [UIDevice currentDevice];
+
+ NSString *osVersion = currentDevice.systemVersion;
+
+ NSString *screenSize = [NSString stringWithFormat:@"%.fx%.f", [UIScreen mainScreen].bounds.size.width,
+ [UIScreen mainScreen].bounds.size.height];
+
+ NSLocale *currentLocale = [NSLocale currentLocale];
+ NSString *country = [currentLocale objectForKey:NSLocaleCountryCode];
+
+ NSString *device = deviceName();
+
+ const NXArchInfo localArchInfo = *NXGetLocalArchInfo();
+ NSString *abi = [NSString stringWithUTF8String:localArchInfo.description];
+
+ NSString *ram = [NSString stringWithFormat:@"%llu", [NSProcessInfo processInfo].physicalMemory];
+
+ NSString *os = currentDevice.systemName;
+
+ sharedConfiguration.metadata = @{ @"version" : osVersion,
+ @"screenSize" : screenSize,
+ @"country" : country,
+ @"device" : device,
+ @"abi" : abi,
+ @"brand" : @"Apple",
+ @"ram" : ram,
+ @"os" : os
+ };
+#endif
});
return sharedConfiguration;
}
@@ -41,8 +76,19 @@ NSString* MGLStringFromMetricType(MGLMetricType metricType) {
#if TARGET_OS_IOS
- (void)pushMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes {
NSString *eventName = MGLStringFromMetricType(metricType);
+ NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes];
+ [mutableAttributes setObject:self.metadata forKey:@"metadata"];
+
+ [MGLMapboxEvents pushEvent:eventName withAttributes:mutableAttributes];
+}
+
+NSString* deviceName()
+{
+ struct utsname systemInfo;
+ uname(&systemInfo);
- [MGLMapboxEvents pushEvent:eventName withAttributes:attributes];
+ return [NSString stringWithCString:systemInfo.machine
+ encoding:NSUTF8StringEncoding];
}
#endif