diff options
author | Alex Zolotarev <alex@maps.me> | 2015-09-02 00:18:25 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:03:33 +0300 |
commit | b099af7f137238f24af00729f4d1c04d543212ff (patch) | |
tree | 27557bc090305d019713b959e0f56bdfc172c856 /3party/Alohalytics/src/apple/alohalytics_objc.mm | |
parent | 7e9beccb4c5bf3470c5da5063938cb9cafa6ddb6 (diff) |
[alohalytics][ios] Integrated enable/disable statistics code with iOS part.
Diffstat (limited to '3party/Alohalytics/src/apple/alohalytics_objc.mm')
-rw-r--r-- | 3party/Alohalytics/src/apple/alohalytics_objc.mm | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/3party/Alohalytics/src/apple/alohalytics_objc.mm b/3party/Alohalytics/src/apple/alohalytics_objc.mm index cbd655cc79..8439d89530 100644 --- a/3party/Alohalytics/src/apple/alohalytics_objc.mm +++ b/3party/Alohalytics/src/apple/alohalytics_objc.mm @@ -288,7 +288,7 @@ static void OnUploadFinished(alohalytics::ProcessingResult result) { } EndBackgroundTask(); } - +#endif // TARGET_OS_IPHONE // Quick check if device has any active connection. // Does not guarantee actual reachability of any host. // Inspired by Apple's Reachability example: @@ -315,19 +315,22 @@ bool IsConnectionActive() { && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) { return true; } +#if (TARGET_OS_IPHONE > 0) if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) { return true; } +#endif // TARGET_OS_IPHONE return false; } -#endif // TARGET_OS_IPHONE +//#endif // TARGET_OS_IPHONE } // namespace // Keys for NSUserDefaults. static NSString * const kInstalledVersionKey = @"AlohalyticsInstalledVersion"; static NSString * const kFirstLaunchDateKey = @"AlohalyticsFirstLaunchDate"; static NSString * const kTotalSecondsInTheApp = @"AlohalyticsTotalSecondsInTheApp"; +static NSString * const kIsAlohalyticsDisabledKey = @"AlohalyticsDisabledKey"; // Used to calculate session length and total time spent in the app. // setup should be called to activate counting. @@ -371,8 +374,11 @@ static BOOL gIsFirstSession = NO; .SetStoragePath(StoragePath()); NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + if ([ud boolForKey:kIsAlohalyticsDisabledKey]) { + instance.Disable(); + } + // Calculate some basic statistics about installations/updates/launches. - NSUserDefaults * userDataBase = [NSUserDefaults standardUserDefaults]; NSString * installedVersion = [ud objectForKey:kInstalledVersionKey]; BOOL shouldSendUpdatedSystemInformation = NO; // Do not generate $install event for old users who did not have Alohalytics installed but already used the app. @@ -563,4 +569,25 @@ static BOOL gIsFirstSession = NO; return [Alohalytics fileCreationDate:[[NSBundle mainBundle] executablePath]]; } ++ (void)disable { + Stats & s = Stats::Instance(); + s.LogEvent("$statisticsDisabled"); + // Force uploading of all previous events. + if (IsConnectionActive()) + s.Upload(); + s.Disable(); + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + [ud setBool:YES forKey:kIsAlohalyticsDisabledKey]; + [ud synchronize]; +} + ++ (void)enable { + Stats & s = Stats::Instance(); + s.Enable(); + s.LogEvent("$statisticsEnabled"); + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + [ud setBool:NO forKey:kIsAlohalyticsDisabledKey]; + [ud synchronize]; +} + @end |