diff options
author | Sergey Yershov <syershov@maps.me> | 2016-10-25 15:10:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-25 15:10:58 +0300 |
commit | 87ca29db2db2865fefe3cf591e2009a5e6ecd452 (patch) | |
tree | d165640da8a3acb2ad0c1698aba7c03691ab368d | |
parent | 97517485578e77facbf05b05f0eb841a54aa74fd (diff) | |
parent | dea0c7590b90bd3e66e1ac24865db64fdc3f7b69 (diff) |
Merge pull request #4549 from igrechuhin/statistics
[ios] Updated initial statistics state to enabled.
m--------- | 3party/Alohalytics | 0 | ||||
-rw-r--r-- | iphone/Maps/MWMSettings.h | 1 | ||||
-rw-r--r-- | iphone/Maps/MWMSettings.mm | 19 | ||||
-rw-r--r-- | iphone/Maps/Settings/MWMSettingsViewController.mm | 5 | ||||
-rw-r--r-- | iphone/Maps/Statistics/Statistics.h | 4 | ||||
-rw-r--r-- | iphone/Maps/Statistics/Statistics.mm | 84 |
6 files changed, 36 insertions, 77 deletions
diff --git a/3party/Alohalytics b/3party/Alohalytics -Subproject 6fc3b425c324855b3a8bfdce706bdb32b1947ce +Subproject a3e1659ba90ed079b3021ea2fa45a628a832b8e diff --git a/iphone/Maps/MWMSettings.h b/iphone/Maps/MWMSettings.h index 3e6772383c..777628c2d3 100644 --- a/iphone/Maps/MWMSettings.h +++ b/iphone/Maps/MWMSettings.h @@ -20,6 +20,7 @@ + (void)setCompassCalibrationEnabled:(BOOL)compassCalibrationEnabled; + (BOOL)statisticsEnabled; ++ (void)setStatisticsEnabled:(BOOL)statisticsEnabled; + (BOOL)autoNightModeEnabled; + (void)setAutoNightModeEnabled:(BOOL)autoNightModeEnabled; diff --git a/iphone/Maps/MWMSettings.mm b/iphone/Maps/MWMSettings.mm index 8c92713de9..7066547a39 100644 --- a/iphone/Maps/MWMSettings.mm +++ b/iphone/Maps/MWMSettings.mm @@ -1,12 +1,12 @@ #import "MWMSettings.h" #import "MWMMapViewControlsManager.h" +#import "3party/Alohalytics/src/alohalytics_objc.h" + #include "Framework.h" #include "platform/settings.hpp" -extern char const * kStatisticsEnabledSettingsKey; - namespace { char const * kAdForbiddenSettingsKey = "AdForbidden"; @@ -15,6 +15,7 @@ char const * kAutoDownloadEnabledKey = "AutoDownloadEnabled"; char const * kZoomButtonsEnabledKey = "ZoomButtonsEnabled"; char const * kCompassCalibrationEnabledKey = "CompassCalibrationEnabled"; char const * kRoutingDisclaimerApprovedKey = "IsDisclaimerApproved"; +char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; NSString * const kUDAutoNightModeOff = @"AutoNightModeOff"; NSString * const kSpotlightLocaleLanguageId = @"SpotlightLocaleLanguageId"; @@ -98,6 +99,20 @@ NSString * const kSpotlightLocaleLanguageId = @"SpotlightLocaleLanguageId"; return enabled; } ++ (void)setStatisticsEnabled:(BOOL)statisticsEnabled +{ + if (statisticsEnabled) + { + [Alohalytics enable]; + } + else + { + [Alohalytics logEvent:@"statisticsDisabled"]; + [Alohalytics disable]; + } + settings::Set(kStatisticsEnabledSettingsKey, static_cast<bool>(statisticsEnabled)); +} + + (BOOL)autoNightModeEnabled { return ![[NSUserDefaults standardUserDefaults] boolForKey:kUDAutoNightModeOff]; diff --git a/iphone/Maps/Settings/MWMSettingsViewController.mm b/iphone/Maps/Settings/MWMSettingsViewController.mm index 2a140cfb28..5f3334c19d 100644 --- a/iphone/Maps/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMSettingsViewController.mm @@ -191,10 +191,7 @@ extern NSString * const kAlohalyticsTapEventKey; kStatAction : kStatToggleStatistics, kStatValue : (value ? kStatOn : kStatOff) }]; - if (value) - [[Statistics instance] enableOnNextAppLaunch]; - else - [[Statistics instance] disableOnNextAppLaunch]; + [MWMSettings setStatisticsEnabled:value]; } else if (cell == self.perspectiveViewCell) { diff --git a/iphone/Maps/Statistics/Statistics.h b/iphone/Maps/Statistics/Statistics.h index 5f19e922ad..53c55371d5 100644 --- a/iphone/Maps/Statistics/Statistics.h +++ b/iphone/Maps/Statistics/Statistics.h @@ -1,10 +1,6 @@ #import "StatisticsStrings.h" @interface Statistics : NSObject -+ (bool)isStatisticsEnabledByDefault; -- (bool)isStatisticsEnabled; -- (void)enableOnNextAppLaunch; -- (void)disableOnNextAppLaunch; // Should be called from the same method in AppDelegate. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; diff --git a/iphone/Maps/Statistics/Statistics.mm b/iphone/Maps/Statistics/Statistics.mm index 476be88b90..ca73884552 100644 --- a/iphone/Maps/Statistics/Statistics.mm +++ b/iphone/Maps/Statistics/Statistics.mm @@ -1,6 +1,7 @@ +#import "Statistics.h" #import "AppInfo.h" #import "MWMCustomFacebookEvents.h" -#import "Statistics.h" +#import "MWMSettings.h" #import "3party/Alohalytics/src/alohalytics_objc.h" #import "Flurry.h" @@ -10,78 +11,23 @@ #include "platform/settings.hpp" +#include "base/macros.hpp" + // If you have a "missing header error" here, then please run configure.sh script in the root repo folder. #import "../../../private.h" -char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; - @interface Statistics () -{ - bool _enabled; -} -@property (nonatomic) NSDate * lastLocationLogTimestamp; -@end - -@implementation Statistics - -+ (bool)isStatisticsEnabledByDefault -{ -#ifdef OMIM_PRODUCTION - return true; -#else - // Make developer's life a little bit easier. - [Alohalytics setDebugMode:YES]; - return false; -#endif -} - -- (instancetype)init -{ - if ((self = [super init])) - { - _enabled = [Statistics isStatisticsEnabledByDefault]; - // Note by AlexZ: - // _enabled should be persistent across app's process lifecycle. That's why we change - // _enabled property only once - when the app is launched. In this case we don't need additional - // checks and specific initializations for different 3party engines, code is much cleaner and safer - // (actually, we don't have a choice - 3party SDKs do not guarantee correctness if not initialized - // in application:didFinishLaunchingWithOptions:). - // The (only) drawback of this approach is that to actually disable or enable 3party engines, - // the app should be restarted. - (void)settings::Get(kStatisticsEnabledSettingsKey, _enabled); - - if (_enabled) - [Alohalytics enable]; - else - [Alohalytics disable]; - } - return self; -} -- (bool)isStatisticsEnabled -{ - return _enabled; -} +@property(nonatomic) NSDate * lastLocationLogTimestamp; -- (void)enableOnNextAppLaunch -{ - // This setting will be checked and applied on the next launch. - settings::Set(kStatisticsEnabledSettingsKey, true); - // It does not make sense to log statisticsEnabled with Alohalytics here, - // as it will not be stored and logged anyway. -} +@end -- (void)disableOnNextAppLaunch -{ - // This setting will be checked and applied on the next launch. - settings::Set(kStatisticsEnabledSettingsKey, false); - [Alohalytics logEvent:@"statisticsDisabled"]; -} +@implementation Statistics - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // _enabled should be already correctly set up in init method. - if (_enabled) + if ([MWMSettings statisticsEnabled]) { [Flurry startSession:@(FLURRY_KEY)]; [Flurry logAllPageViewsForTarget:application.windows.firstObject.rootViewController]; @@ -101,7 +47,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; - (void)logLocation:(CLLocation *)location { - if (!_enabled) + if (![MWMSettings statisticsEnabled]) return; if (!_lastLocationLogTimestamp || [[NSDate date] timeIntervalSinceDate:_lastLocationLogTimestamp] > (60 * 60 * 3)) { @@ -113,7 +59,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; - (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters { - if (!_enabled) + if (![MWMSettings statisticsEnabled]) return; NSMutableDictionary * params = [self addDefaultAttributesToParameters:parameters]; [Flurry logEvent:eventName withParameters:params]; @@ -122,7 +68,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; - (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters atLocation:(CLLocation *)location { - if (!_enabled) + if (![MWMSettings statisticsEnabled]) return; NSMutableDictionary * params = [self addDefaultAttributesToParameters:parameters]; [Alohalytics logEvent:eventName withDictionary:params atLocation:location]; @@ -152,7 +98,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; - (void)logApiUsage:(NSString *)programName { - if (!_enabled) + if (![MWMSettings statisticsEnabled]) return; if (programName) [self logEvent:@"Api Usage" withParameters: @{@"Application Name" : programName}]; @@ -162,7 +108,7 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; - (void)applicationDidBecomeActive { - if (!_enabled) + if (![MWMSettings statisticsEnabled]) return; [FBSDKAppEvents activateApp]; // Special FB events to improve marketing campaigns quality. @@ -176,6 +122,10 @@ char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled"; dispatch_once(&onceToken, ^ { instance = [[Statistics alloc] init]; + if ([MWMSettings statisticsEnabled]) + [Alohalytics enable]; + else + [Alohalytics disable]; }); return instance; } |