@@ -1710,14 +1710,24 @@ + (BOOL)shouldRegisterNow {
17101710 // Make sure last time we closed app was more than 30 secs ago
17111711 const int minTimeThreshold = 30 ;
17121712 NSTimeInterval delta = now - lastTimeClosed;
1713+
1714+ // Tracking cold starts within 30 seconds of last close.
1715+ // Depending on the results of our tracking we will change this case
1716+ // from a tracking request to return true
17131717 if (delta < minTimeThreshold && appId && !_registerUserFinished && !_trackedColdRestart) {
1714- NSString *osUsageData = [NSString stringWithFormat: @" lib-name=OneSignal-iOS-SDK,lib-version=%@ ,lib-event=cold_restart" , ONESIGNAL_VERSION];
1718+ [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" shouldRegisterNow:coldRestart" ];
1719+ // Set to true even if it doesn't pass the sample check
17151720 _trackedColdRestart = true ;
1716- [[OneSignalClient sharedClient ] executeRequest: [OSRequestTrackV1 trackUsageData: osUsageData appId: appId] onSuccess: ^(NSDictionary *result) {
1717- [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" shouldRegisterNow:trackColdRestart: successfully tracked cold restart" ];
1718- } onFailure: ^(NSError *error) {
1719- [OneSignal onesignal_Log: ONE_S_LL_ERROR message: [NSString stringWithFormat: @" shouldRegisterNow:trackColdRestart: Failed to track cold restart: %@ " , error.localizedDescription]];
1720- }];
1721+ // Sample /track calls to avoid hitting our endpoint too hard
1722+ int randomSample = arc4random_uniform (100 );
1723+ if (randomSample == 99 ) {
1724+ NSString *osUsageData = [NSString stringWithFormat: @" lib-name=OneSignal-iOS-SDK,lib-version=%@ ,lib-event=cold_restart" , ONESIGNAL_VERSION];
1725+ [[OneSignalClient sharedClient ] executeRequest: [OSRequestTrackV1 trackUsageData: osUsageData appId: appId] onSuccess: ^(NSDictionary *result) {
1726+ [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" shouldRegisterNow:trackColdRestart: successfully tracked cold restart" ];
1727+ } onFailure: ^(NSError *error) {
1728+ [OneSignal onesignal_Log: ONE_S_LL_ERROR message: [NSString stringWithFormat: @" shouldRegisterNow:trackColdRestart: Failed to track cold restart: %@ " , error.localizedDescription]];
1729+ }];
1730+ }
17211731 }
17221732 return delta >= minTimeThreshold;
17231733}
0 commit comments