diff --git a/include/mbgl/ios/MGLMapboxEvents.h b/include/mbgl/ios/MGLMapboxEvents.h index c0cff7c2b..bb28ec26c 100644 --- a/include/mbgl/ios/MGLMapboxEvents.h +++ b/include/mbgl/ios/MGLMapboxEvents.h @@ -21,4 +21,6 @@ - (void) pushEvent:(NSString *)event withAttributes:(NSDictionary *)attributeDictionary; +- (void) flush; + @end \ No newline at end of file diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 000e63956..82114672d 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -407,10 +407,6 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; email = [NSString stringWithFormat:@"%i", sendMail]; } [evt setValue:email forKey:@"enabled.email"]; - - - - }); return YES; @@ -590,6 +586,9 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; - (void)appDidBackground:(NSNotification *)notification { + // Flush Any Events Still In Queue + [[MGLMapboxEvents sharedManager] flush]; + mbglMap->stop(); [self.glView deleteDrawable]; diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 5c5442444..a91a0ed94 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -156,13 +156,17 @@ NSNumber *scale; return; } + + int upper = (int)_flushAt; if (_flushAt > [_queue count]) { - NSLog(@"flush() flushAt (%lu) is greater than current queue count (%lu) so just return", _flushAt, [_queue count]); - return; + if ([_queue count] == 0) { + return; + } + upper = (int)[_queue count]; } // Create Array of Events to push to the Server - NSRange theRange = NSMakeRange(0, (int)_flushAt); + NSRange theRange = NSMakeRange(0, upper); NSArray *events = [_queue subarrayWithRange:theRange]; // Update Queue to remove events sent to server