Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/iphone
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2015-09-04 06:17:37 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:04:06 +0300
commitc3ab639c71a6b8fac8f78f688e223db955dcc0aa (patch)
tree880e66112bfd95eaa3077a86cae39aeef43e1531 /iphone
parent229f4e52351d2a7a9232c86f419f6332cb395fd0 (diff)
[ios] Correctly enable/disable all 3party statistics depending on user’s setting.
Diffstat (limited to 'iphone')
-rw-r--r--iphone/Maps/Settings/SettingsViewController.mm11
-rw-r--r--iphone/Maps/Statistics/Statistics.h8
-rw-r--r--iphone/Maps/Statistics/Statistics.mm91
3 files changed, 71 insertions, 39 deletions
diff --git a/iphone/Maps/Settings/SettingsViewController.mm b/iphone/Maps/Settings/SettingsViewController.mm
index 086852f323..79bef8a4c1 100644
--- a/iphone/Maps/Settings/SettingsViewController.mm
+++ b/iphone/Maps/Settings/SettingsViewController.mm
@@ -15,6 +15,8 @@
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
+extern char const * kStatisticsEnabledSettingsKey;
+
typedef NS_ENUM(NSUInteger, Section)
{
SectionMetrics,
@@ -82,8 +84,8 @@ typedef NS_ENUM(NSUInteger, Section)
{
cell = [tableView dequeueReusableCellWithIdentifier:[SwitchCell className]];
SwitchCell * customCell = (SwitchCell *)cell;
- bool on = true;
- (void)Settings::Get("StatisticsEnabled", on);
+ bool on = [Statistics isStatisticsEnabledByDefault];
+ (void)Settings::Get(kStatisticsEnabledSettingsKey, on);
customCell.switchButton.on = on;
customCell.titleLabel.text = L(@"allow_statistics");
customCell.delegate = self;
@@ -128,7 +130,10 @@ typedef NS_ENUM(NSUInteger, Section)
{
Statistics * stat = [Statistics instance];
[stat logEvent:@"StatisticsStatusChanged" withParameters:@{@"Enabled" : @(value)}];
- stat.enabled = value;
+ if (value)
+ [stat enableOnNextAppLaunch];
+ else
+ [stat disableOnNextAppLaunch];
}
else if (indexPath.section == SectionZoomButtons)
{
diff --git a/iphone/Maps/Statistics/Statistics.h b/iphone/Maps/Statistics/Statistics.h
index ef5a239d85..ee6a8046d0 100644
--- a/iphone/Maps/Statistics/Statistics.h
+++ b/iphone/Maps/Statistics/Statistics.h
@@ -1,8 +1,9 @@
#import <Foundation/Foundation.h>
@interface Statistics : NSObject
-{
-}
++ (bool)isStatisticsEnabledByDefault;
+- (void)enableOnNextAppLaunch;
+- (void)disableOnNextAppLaunch;
// Should be called from the same method in AppDelegate.
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
@@ -14,7 +15,4 @@
- (void)logLocation:(CLLocation *)location;
+ (instancetype)instance;
-
-@property (nonatomic) BOOL enabled;
-
@end
diff --git a/iphone/Maps/Statistics/Statistics.mm b/iphone/Maps/Statistics/Statistics.mm
index b8c49b07cf..bf28a5f639 100644
--- a/iphone/Maps/Statistics/Statistics.mm
+++ b/iphone/Maps/Statistics/Statistics.mm
@@ -10,17 +10,70 @@
#include "platform/settings.hpp"
-static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled";
+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;
+}
+
+- (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.
+}
+
+- (void)disableOnNextAppLaunch
+{
+ // This setting will be checked and applied on the next launch.
+ Settings::Set(kStatisticsEnabledSettingsKey, false);
+ [Alohalytics logEvent:@"statisticsDisabled"];
+}
+
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- if (self.enabled)
+ // _enabled should be already correctly set up in init method.
+ if (_enabled)
{
[Flurry startSession:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlurryKey"]];
@@ -30,20 +83,16 @@ static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled
#ifdef DEBUG
[MRMyTracker setDebugMode:YES];
#endif
- MRMyTracker.getTrackerParams.trackAppLaunch = YES;
+ [MRMyTracker getTrackerParams].trackAppLaunch = YES;
[MRMyTracker setupTracker];
- // Initialize Alohalytics statistics engine.
-#ifndef OMIM_PRODUCTION
- [Alohalytics setDebugMode:YES];
-#endif
[Alohalytics setup:@"http://localhost:8080" withLaunchOptions:launchOptions];
}
}
- (void)logLocation:(CLLocation *)location
{
- if (self.enabled)
+ if (_enabled)
{
if (!_lastLocationLogTimestamp || [[NSDate date] timeIntervalSinceDate:_lastLocationLogTimestamp] > (60 * 60 * 3))
{
@@ -56,7 +105,7 @@ static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled
- (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters
{
- if (self.enabled)
+ if (_enabled)
[Flurry logEvent:eventName withParameters:parameters];
}
@@ -67,7 +116,7 @@ static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled
- (void)logApiUsage:(NSString *)programName
{
- if (self.enabled)
+ if (_enabled)
{
if (programName)
[self logEvent:@"Api Usage" withParameters: @{@"Application Name" : programName}];
@@ -78,7 +127,7 @@ static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled
- (void)applicationDidBecomeActive
{
- if (self.enabled)
+ if (_enabled)
{
[FBSDKAppEvents activateApp];
// Special FB events to improve marketing campaigns quality.
@@ -86,26 +135,6 @@ static constexpr char const * kStatisticsEnabledSettingsKey = "StatisticsEnabled
}
}
-- (BOOL)enabled
-{
-#ifdef DEBUG
- bool statisticsEnabled = false;
-#else
- bool statisticsEnabled = true;
-#endif
- (void)Settings::Get(kStatisticsEnabledSettingsKey, statisticsEnabled);
- return statisticsEnabled;
-}
-
-- (void)setEnabled:(BOOL)enabled
-{
- Settings::Set(kStatisticsEnabledSettingsKey, static_cast<bool>(enabled));
- if (enabled)
- [Alohalytics enable];
- else
- [Alohalytics disable];
-}
-
+ (instancetype)instance
{
static Statistics * instance;