From 97500d55ecea6a776ce43786f075fe7d686d842b Mon Sep 17 00:00:00 2001 From: Thomas Guillet Date: Thu, 8 Dec 2016 10:47:10 +0100 Subject: [PATCH] Prevent iRate mechanism when handling local notifications --- Libraries/iRate/iRate.h | 1 + Libraries/iRate/iRate.m | 14 ++++++++++++++ Signal/src/AppDelegate.m | 1 + Signal/src/util/AppStoreRating.h | 1 + Signal/src/util/AppStoreRating.m | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/Libraries/iRate/iRate.h b/Libraries/iRate/iRate.h index 8d40e77c2..eeae1724d 100755 --- a/Libraries/iRate/iRate.h +++ b/Libraries/iRate/iRate.h @@ -165,6 +165,7 @@ typedef NS_ENUM(NSUInteger, iRateErrorCode) { - (void)promptIfAllCriteriaMet; - (void)openRatingsPageInAppStore; - (void)logEvent:(BOOL)deferPrompt; +- (void)preventPromptAtNextTest; @end diff --git a/Libraries/iRate/iRate.m b/Libraries/iRate/iRate.m index 709328f2c..258cc1eb4 100755 --- a/Libraries/iRate/iRate.m +++ b/Libraries/iRate/iRate.m @@ -128,6 +128,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple @property (nonatomic, strong) id visibleAlert; @property (nonatomic, assign) BOOL checkingForPrompt; @property (nonatomic, assign) BOOL checkingForAppStoreID; +@property (nonatomic, assign) BOOL shouldPreventPromptAtNextTest; @end @@ -224,6 +225,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple self.remindPeriod = 1.0f; self.verboseLogging = NO; self.previewMode = NO; + self.shouldPreventPromptAtNextTest = NO; #if DEBUG @@ -404,6 +406,10 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple [[NSNotificationCenter defaultCenter] removeObserver:self]; } +- (void)preventPromptAtNextTest { + self.shouldPreventPromptAtNextTest = YES; +} + - (void)incrementUseCount { self.usesCount++; } @@ -413,6 +419,14 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple } - (BOOL)shouldPromptForRating { + // Avoid potentially inconvenient prompt + if (self.shouldPreventPromptAtNextTest) + { + NSLog(@"iRate did not prompt for rating because it is potentially inconvenient"); + self.shouldPreventPromptAtNextTest = NO; + return NO; + } + // preview mode? if (self.previewMode) { NSLog(@"iRate preview mode is enabled - make sure you disable this for release"); diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 5f95c0f2e..bf9e9904a 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -332,6 +332,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { + [AppStoreRating preventPromptAtNextTest]; [[PushManager sharedManager] application:application didReceiveLocalNotification:notification]; } diff --git a/Signal/src/util/AppStoreRating.h b/Signal/src/util/AppStoreRating.h index 210a513ec..0568f0919 100644 --- a/Signal/src/util/AppStoreRating.h +++ b/Signal/src/util/AppStoreRating.h @@ -11,5 +11,6 @@ @interface AppStoreRating : NSObject + (void)setupRatingLibrary; ++ (void)preventPromptAtNextTest; @end diff --git a/Signal/src/util/AppStoreRating.m b/Signal/src/util/AppStoreRating.m index f2ddbcd0a..e602831b7 100644 --- a/Signal/src/util/AppStoreRating.m +++ b/Signal/src/util/AppStoreRating.m @@ -25,4 +25,8 @@ rate.rateButtonLabel = NSLocalizedString(@"RATING_RATE", nil); } ++ (void)preventPromptAtNextTest { + iRate *rate = [iRate sharedInstance]; + [rate preventPromptAtNextTest]; +} @end