summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/ios/MGLMapView.mm28
-rw-r--r--platform/ios/MGLMapboxEvents.m114
2 files changed, 78 insertions, 64 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 54bcbec797..7a3a742a6a 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -395,14 +395,12 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
// Fire map.load on a background thread
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSMutableDictionary *evt = [[NSMutableDictionary alloc] init];
[evt setValue:[[NSNumber alloc] initWithDouble:mbglMap->getLatLng().latitude] forKey:@"lat"];
[evt setValue:[[NSNumber alloc] initWithDouble:mbglMap->getLatLng().longitude] forKey:@"lng"];
[evt setValue:[[NSNumber alloc] initWithDouble:mbglMap->getZoom()] forKey:@"zoom"];
- [[MGLMapboxEvents sharedManager] pushEvent:@"map.load" withAttributes:evt];
-
[evt setValue:[[NSNumber alloc] initWithBool:[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]] forKey:@"enabled.push"];
NSString *email = @"Unknown";
@@ -413,6 +411,8 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
email = [NSString stringWithFormat:@"%i", sendMail];
}
[evt setValue:email forKey:@"enabled.email"];
+
+ [[MGLMapboxEvents sharedManager] pushEvent:@"map.load" withAttributes:evt];
});
return YES;
@@ -1032,16 +1032,18 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)trackGestureEvent:(NSString *)gesture forRecognizer:(UIGestureRecognizer *)recognizer
{
- // Send Map Zoom Event
- CGPoint ptInView = CGPointMake([recognizer locationInView:recognizer.view].x, [recognizer locationInView:recognizer.view].y);
- CLLocationCoordinate2D coord = [self convertPoint:ptInView toCoordinateFromView:recognizer.view];
- NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
- [dict setValue:[[NSNumber alloc] initWithDouble:coord.latitude] forKey:@"lat"];
- [dict setValue:[[NSNumber alloc] initWithDouble:coord.longitude] forKey:@"lng"];
- [dict setValue:[[NSNumber alloc] initWithDouble:[self zoomLevel]] forKey:@"zoom"];
- [dict setValue:gesture forKey:@"gesture"];
-
- [[MGLMapboxEvents sharedManager] pushEvent:@"map.click" withAttributes:dict];
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
+ // Send Map Zoom Event
+ CGPoint ptInView = CGPointMake([recognizer locationInView:recognizer.view].x, [recognizer locationInView:recognizer.view].y);
+ CLLocationCoordinate2D coord = [self convertPoint:ptInView toCoordinateFromView:recognizer.view];
+ NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
+ [dict setValue:[[NSNumber alloc] initWithDouble:coord.latitude] forKey:@"lat"];
+ [dict setValue:[[NSNumber alloc] initWithDouble:coord.longitude] forKey:@"lng"];
+ [dict setValue:[[NSNumber alloc] initWithDouble:[self zoomLevel]] forKey:@"zoom"];
+ [dict setValue:gesture forKey:@"gesture"];
+
+ [[MGLMapboxEvents sharedManager] pushEvent:@"map.click" withAttributes:dict];
+ });
}
#pragma mark - Properties -
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index 5a9bd94557..8a037f18f5 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -23,6 +23,8 @@
@property (atomic) NSString *anonid;
@property (atomic) NSTimer *timer;
@property (atomic) NSString *userAgent;
+@property (atomic) dispatch_queue_t serialqPush;
+@property (atomic) dispatch_queue_t serialqFlush;
@end
@@ -57,6 +59,10 @@ NSNumber *scale;
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
}
+ NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
+ NSString *uniqueID = [[NSProcessInfo processInfo] globallyUniqueString];
+ _serialqPush = dispatch_queue_create([[NSString stringWithFormat:@"%@.%@.SERIALQPUSH", bundleID, uniqueID] UTF8String], DISPATCH_QUEUE_SERIAL);
+ _serialqFlush = dispatch_queue_create([[NSString stringWithFormat:@"%@.%@.SERIALQFLUSH", bundleID, uniqueID] UTF8String], DISPATCH_QUEUE_SERIAL);
// Configure Events Infrastructure
_queue = [[NSMutableArray alloc] init];
@@ -132,43 +138,47 @@ NSNumber *scale;
return;
}
- NSMutableDictionary *evt = [[NSMutableDictionary alloc] init];
- // mapbox-events stock attributes
- [evt setObject:event forKey:@"event"];
- [evt setObject:[NSNumber numberWithInt:1] forKey:@"version"];
- [evt setObject:[self formatDate:[NSDate date]] forKey:@"created"];
- [evt setObject:self.instance forKey:@"instance"];
- [evt setObject:self.anonid forKey:@"anonid"];
-
- // mapbox-events-ios stock attributes
- [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"];
-
- for (NSString *key in [attributeDictionary allKeys]) {
- [evt setObject:[attributeDictionary valueForKey:key] forKey:key];
- }
-
- // Make Immutable Version
- NSDictionary *finalEvent = [NSDictionary dictionaryWithDictionary:evt];
-
- // Put On The Queue
- [self.queue addObject:finalEvent];
-
- // Has Flush Limit Been Reached?
- if ((int)_queue.count >= (int)_flushAt) {
- [self flush];
- }
-
- // Reset Timer (Initial Starting of Timer after first event is pushed)
- [self startTimer];
+ dispatch_async(_serialqPush, ^{
+
+ NSMutableDictionary *evt = [[NSMutableDictionary alloc] init];
+ // mapbox-events stock attributes
+ [evt setObject:event forKey:@"event"];
+ [evt setObject:[NSNumber numberWithInt:1] forKey:@"version"];
+ [evt setObject:[self formatDate:[NSDate date]] forKey:@"created"];
+ [evt setObject:self.instance forKey:@"instance"];
+ [evt setObject:self.anonid forKey:@"anonid"];
+
+ // mapbox-events-ios stock attributes
+ [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"];
+
+ for (NSString *key in [attributeDictionary allKeys]) {
+ [evt setObject:[attributeDictionary valueForKey:key] forKey:key];
+ }
+
+ // Make Immutable Version
+ NSDictionary *finalEvent = [NSDictionary dictionaryWithDictionary:evt];
+
+ // Put On The Queue
+ [self.queue addObject:finalEvent];
+
+ // Has Flush Limit Been Reached?
+ if ((int)_queue.count >= (int)_flushAt) {
+ [self flush];
+ }
+
+ // Reset Timer (Initial Starting of Timer after first event is pushed)
+ [self startTimer];
+
+ });
}
- (void) flush {
@@ -176,24 +186,26 @@ NSNumber *scale;
return;
}
- int upper = (int)_flushAt;
- if (_flushAt > [_queue count]) {
- if ([_queue count] == 0) {
- return;
- }
- upper = (int)[_queue count];
- }
+ dispatch_async(_serialqFlush, ^{
- // Create Array of Events to push to the Server
- NSRange theRange = NSMakeRange(0, upper);
- NSArray *events = [_queue subarrayWithRange:theRange];
+ int upper = (int)_flushAt;
+ if (_flushAt > [_queue count]) {
+ if ([_queue count] == 0) {
+ return;
+ }
+ upper = (int)[_queue count];
+ }
- // Update Queue to remove events sent to server
- [_queue removeObjectsInRange:theRange];
+ // Create Array of Events to push to the Server
+ NSRange theRange = NSMakeRange(0, upper);
+ NSArray *events = [_queue subarrayWithRange:theRange];
- // Send Array of Events to Server
- [self postEvents:events];
+ // Update Queue to remove events sent to server
+ [_queue removeObjectsInRange:theRange];
+ // Send Array of Events to Server
+ [self postEvents:events];
+ });
}
- (void) postEvents:(NSArray *)events {