Merge pull request #1086 from mapbox/metrics-enhancements

Enhancements Since Original Merge
This commit is contained in:
Brad Leege
2015-03-24 21:37:50 -05:00
2 changed files with 38 additions and 28 deletions

View File

@@ -118,14 +118,12 @@ NSNumber *scale;
// Opt Out Checking When Built
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"mapbox_metrics_enabled_preference"]) {
NSLog(@"Mapbox Metrics are not enabled, so clear any currently stored events, and return without sending in data.");
[_queue removeAllObjects];
return;
}
// Add Metrics Disabled App Wide Check
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"mapbox_metrics_disabled"] != nil) {
NSLog(@"Mapbox Metrics have been disabled for this app.");
[_queue removeAllObjects];
return;
}
@@ -143,13 +141,14 @@ NSNumber *scale;
[evt setObject:self.anonid forKey:@"anonid"];
// mapbox-events-ios stock attributes
[evt setValue:[rfc3339DateFormatter stringFromDate:[NSDate date]] forKey:@"deviceTimestamp"];
[evt setValue:[rfc3339DateFormatter stringFromDate:[NSDate date]] forKey:@"created"];
[evt setValue:model forKey:@"model"];
[evt setValue:iOSVersion forKey:@"operatingSystem"];
[evt setValue:[self getDeviceOrientation] forKey:@"orientation"];
[evt setValue:[[NSNumber alloc] initWithFloat:(100 * [UIDevice currentDevice].batteryLevel)] forKey:@"batteryLevel"];
[evt setValue:scale forKey:@"resolution"];
[evt setValue:carrier forKey:@"carrier"];
[evt setValue:[self getCurrentCellularNetworkConnectionType] forKey:@"cellularNetworkType"];
[evt setValue:[self getWifiNetworkName] forKey:@"wifi"];
[evt setValue:[NSNumber numberWithInt:[self getContentSizeScale]] forKey:@"accessibilityFontScale"];
@@ -174,7 +173,6 @@ NSNumber *scale;
- (void) flush {
if (_token == nil) {
NSLog(@"token hasn't been set yet, so no events can be sent. return");
return;
}
@@ -324,14 +322,48 @@ NSNumber *scale;
if (info) {
ssid = info[@"SSID"];
} else {
ssid = @"<<NONE>>";
ssid = @"NONE";
}
} else {
ssid = @"<<NONE>>";
ssid = @"NONE";
}
return ssid;
}
- (NSString *) getCurrentCellularNetworkConnectionType {
CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSString *radioTech = telephonyInfo.currentRadioAccessTechnology;
if (radioTech == nil) {
return @"NONE";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyGPRS]) {
return @"GPRS";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyEdge]) {
return @"EDGE";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyWCDMA]) {
return @"WCDMA";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyHSDPA]) {
return @"HSDPA";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyHSUPA]) {
return @"HSUPA";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
return @"CDMA1x";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
return @"CDMAEVDORev0";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
return @"CDMAEVDORevA";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
return @"CDMAEVDORevB";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyeHRPD]) {
return @"HRPD";
} else if ([radioTech isEqualToString:CTRadioAccessTechnologyLTE]) {
return @"LTE";
} else {
return @"Unknown";
}
}
@end

View File

@@ -25,24 +25,6 @@ static MGLMetricsLocationManager *sharedManager = nil;
- (id) init {
if (self = [super init]) {
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
if(!settingsBundle) {
NSLog(@"Could not find Settings.bundle");
} else {
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
for(NSDictionary *prefSpecification in preferences) {
NSString *key = [prefSpecification objectForKey:@"Key"];
if(key && [[prefSpecification allKeys] containsObject:@"DefaultValue"]) {
[defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
}
_locationManager = [[CLLocationManager alloc] init];
_locationManager.distanceFilter = 2;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
@@ -83,9 +65,6 @@ static MGLMetricsLocationManager *sharedManager = nil;
#pragma mark CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *loc = (CLLocation *)[locations objectAtIndex:0];
NSLog(@"didUpdateLocations() called with %lu location in array. First Location = %f, %f", (unsigned long)locations.count, loc.coordinate.latitude, loc.coordinate.longitude);
// Iterate through locations to pass all data
for (CLLocation *loc in locations) {
NSMutableDictionary *evt = [[NSMutableDictionary alloc] init];
@@ -123,7 +102,6 @@ static MGLMetricsLocationManager *sharedManager = nil;
newStatus = @"Unknown";
break;
}
NSLog(@"MGLMetricsLocationManager didChangeAuthorizationStatus() called. New Status = %@", newStatus);
}
@end