summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapboxEvents.m
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src/MGLMapboxEvents.m')
-rw-r--r--platform/ios/src/MGLMapboxEvents.m63
1 files changed, 31 insertions, 32 deletions
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index f5628bc6fb..13540bfd08 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -122,7 +122,8 @@ const NSTimeInterval MGLFlushInterval = 180;
@property (nonatomic) dispatch_queue_t debugLogSerialQueue;
@property (nonatomic) MGLLocationManager *locationManager;
@property (nonatomic) NSTimer *timer;
-@property (nonatomic) NSDate *lastInstanceIDRotationDate;
+@property (nonatomic) NSDate *instanceIDRotationDate;
+@property (nonatomic) NSDate *turnstileSendDate;
@end
@@ -233,13 +234,13 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (NSString *)instanceID {
- if (self.lastInstanceIDRotationDate && [[NSDate date] timeIntervalSinceDate:self.lastInstanceIDRotationDate] >= 0) {
+ if (self.instanceIDRotationDate && [[NSDate date] timeIntervalSinceDate:self.instanceIDRotationDate] >= 0) {
_instanceID = nil;
}
if (!_instanceID) {
_instanceID = [[NSUUID UUID] UUIDString];
NSTimeInterval twentyFourHourTimeInterval = 24 * 3600;
- self.lastInstanceIDRotationDate = [[NSDate date] dateByAddingTimeInterval:twentyFourHourTimeInterval];
+ self.instanceIDRotationDate = [[NSDate date] dateByAddingTimeInterval:twentyFourHourTimeInterval];
}
return _instanceID;
}
@@ -314,38 +315,36 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (void)pushTurnstileEvent {
- __weak MGLMapboxEvents *weakSelf = self;
+ if (self.turnstileSendDate && [[NSDate date] timeIntervalSinceDate:self.turnstileSendDate] < 0) {
+ return;
+ }
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- MGLMapboxEvents *strongSelf = weakSelf;
-
- if (!strongSelf) {
- return;
- }
-
- NSString *vendorID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
- if (!vendorID) {
- return;
- }
-
- NSDictionary *turnstileEventAttributes = @{MGLEventKeyEvent: MGLEventTypeAppUserTurnstile,
- MGLEventKeyCreated: [strongSelf.rfc3339DateFormatter stringFromDate:[NSDate date]],
- MGLEventKeyVendorID: vendorID,
- MGLEventKeyEnabledTelemetry: @([[strongSelf class] isEnabled])};
-
- if ([MGLAccountManager accessToken] == nil) {
+ NSString *vendorID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
+ if (!vendorID) {
+ return;
+ }
+
+ NSDictionary *turnstileEventAttributes = @{MGLEventKeyEvent: MGLEventTypeAppUserTurnstile,
+ MGLEventKeyCreated: [self.rfc3339DateFormatter stringFromDate:[NSDate date]],
+ MGLEventKeyVendorID: vendorID,
+ MGLEventKeyEnabledTelemetry: @([[self class] isEnabled])};
+
+ if ([MGLAccountManager accessToken] == nil) {
+ return;
+ }
+
+ __weak __typeof__(self) weakSelf = self;
+ [self.apiClient postEvent:turnstileEventAttributes completionHandler:^(NSError * _Nullable error) {
+ __strong __typeof__(weakSelf) strongSelf = weakSelf;
+ if (error) {
+ [strongSelf pushDebugEvent:MGLEventTypeLocalDebug withAttributes:@{MGLEventKeyLocalDebugDescription: @"Network error",
+ @"error": error}];
return;
}
- [strongSelf.apiClient postEvent:turnstileEventAttributes completionHandler:^(NSError * _Nullable error) {
- if (error) {
- [strongSelf pushDebugEvent:MGLEventTypeLocalDebug withAttributes:@{MGLEventKeyLocalDebugDescription: @"Network error",
- @"error": error}];
- return;
- }
- [strongSelf writeEventToLocalDebugLog:turnstileEventAttributes];
- }];
- });
+ [strongSelf writeEventToLocalDebugLog:turnstileEventAttributes];
+ NSTimeInterval twentyFourHourTimeInterval = 24 * 3600;
+ strongSelf.turnstileSendDate = [[NSDate date] dateByAddingTimeInterval:twentyFourHourTimeInterval];
+ }];
}
+ (void)pushEvent:(NSString *)event withAttributes:(MGLMapboxEventAttributes *)attributeDictionary {