summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-05-31 08:49:10 -0700
committerJesse Bounds <jesse@rebounds.net>2016-05-31 08:49:10 -0700
commit2ab782b30edf7e4a16fe76738ff227f35f8748f1 (patch)
tree494fe0db4acc7d982ecad1cee27e6045885f211d /platform
parentc4e3f7c5ee6b1b37fb8783b2225888986a8341c4 (diff)
downloadqtlocation-mapboxgl-2ab782b30edf7e4a16fe76738ff227f35f8748f1.tar.gz
[ios] Make turnstile send guard based off of calendar day (#5180)
This improves the turnstile send time guard so that instead of guarding against sending a turnstile event once per 24 hours it guards using a calendar day. This means that, all else being equal, a turnstile can be sent once per day in the same session assuming there is a map load event in that session. A turnstile will always be sent for a map load at the start of a session.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLMapboxEvents.m22
1 files changed, 18 insertions, 4 deletions
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 5b195a3baa..5ddf4e2b57 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -123,7 +123,7 @@ const NSTimeInterval MGLFlushInterval = 180;
@property (nonatomic) MGLLocationManager *locationManager;
@property (nonatomic) NSTimer *timer;
@property (nonatomic) NSDate *instanceIDRotationDate;
-@property (nonatomic) NSDate *turnstileSendDate;
+@property (nonatomic) NSDate *nextTurnstileSendDate;
@end
@@ -315,7 +315,7 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (void)pushTurnstileEvent {
- if (self.turnstileSendDate && [[NSDate date] timeIntervalSinceDate:self.turnstileSendDate] < 0) {
+ if (self.nextTurnstileSendDate && [[NSDate date] timeIntervalSinceDate:self.nextTurnstileSendDate] < 0) {
return;
}
@@ -342,11 +342,25 @@ const NSTimeInterval MGLFlushInterval = 180;
return;
}
[strongSelf writeEventToLocalDebugLog:turnstileEventAttributes];
- NSTimeInterval twentyFourHourTimeInterval = 24 * 3600;
- strongSelf.turnstileSendDate = [[NSDate date] dateByAddingTimeInterval:twentyFourHourTimeInterval];
+ [strongSelf updateNextTurnstileSendDate];
}];
}
+- (void)updateNextTurnstileSendDate {
+ // Find the time a day from now (sometime tomorrow)
+ NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
+ NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
+ dayComponent.day = 1;
+ NSDate *sometimeTomorrow = [calendar dateByAddingComponents:dayComponent toDate:[NSDate date] options:0];
+
+ // Find the start of tomorrow and use that as the next turnstile send date. The effect of this is that
+ // turnstile events can be sent as much as once per calendar day and always at the start of a session
+ // when a map load happens.
+ NSDate *startOfTomorrow = nil;
+ [calendar rangeOfUnit:NSCalendarUnitDay startDate:&startOfTomorrow interval:nil forDate:sometimeTomorrow];
+ self.nextTurnstileSendDate = startOfTomorrow;
+}
+
+ (void)pushEvent:(NSString *)event withAttributes:(MGLMapboxEventAttributes *)attributeDictionary {
[[MGLMapboxEvents sharedManager] pushEvent:event withAttributes:attributeDictionary];
}