#1033 - Flush all events to server when app enters background

This commit is contained in:
Brad Leege
2015-03-24 10:02:13 -05:00
parent 99049dc6b5
commit 3e062d0e20
3 changed files with 12 additions and 7 deletions

View File

@@ -21,4 +21,6 @@
- (void) pushEvent:(NSString *)event withAttributes:(NSDictionary *)attributeDictionary;
- (void) flush;
@end

View File

@@ -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];

View File

@@ -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