Merge branch 'charlesmchen/iRateCrashes' into release/2.24.0

pull/1/head
Matthew Chen 7 years ago
commit af418a98be

@ -130,6 +130,8 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
@property (nonatomic, assign) BOOL checkingForAppStoreID; @property (nonatomic, assign) BOOL checkingForAppStoreID;
@property (nonatomic, assign) BOOL shouldPreventPromptAtNextTest; @property (nonatomic, assign) BOOL shouldPreventPromptAtNextTest;
@property (nonatomic) BOOL hasQueuedSynchronize;
@end @end
@ -180,6 +182,10 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
selector:@selector(applicationWillEnterForeground) selector:@selector(applicationWillEnterForeground)
name:UIApplicationWillEnterForegroundNotification name:UIApplicationWillEnterForegroundNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
} }
#endif #endif
@ -335,7 +341,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setFirstUsed:(NSDate *)date { - (void)setFirstUsed:(NSDate *)date {
[[NSUserDefaults standardUserDefaults] setObject:date forKey:iRateFirstUsedKey]; [[NSUserDefaults standardUserDefaults] setObject:date forKey:iRateFirstUsedKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (NSDate *)lastReminded { - (NSDate *)lastReminded {
@ -344,7 +350,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setLastReminded:(NSDate *)date { - (void)setLastReminded:(NSDate *)date {
[[NSUserDefaults standardUserDefaults] setObject:date forKey:iRateLastRemindedKey]; [[NSUserDefaults standardUserDefaults] setObject:date forKey:iRateLastRemindedKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (NSUInteger)usesCount { - (NSUInteger)usesCount {
@ -353,7 +359,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setUsesCount:(NSUInteger)count { - (void)setUsesCount:(NSUInteger)count {
[[NSUserDefaults standardUserDefaults] setInteger:(NSInteger)count forKey:iRateUseCountKey]; [[NSUserDefaults standardUserDefaults] setInteger:(NSInteger)count forKey:iRateUseCountKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (NSUInteger)eventCount { - (NSUInteger)eventCount {
@ -362,7 +368,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setEventCount:(NSUInteger)count { - (void)setEventCount:(NSUInteger)count {
[[NSUserDefaults standardUserDefaults] setInteger:(NSInteger)count forKey:iRateEventCountKey]; [[NSUserDefaults standardUserDefaults] setInteger:(NSInteger)count forKey:iRateEventCountKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (float)usesPerWeek { - (float)usesPerWeek {
@ -377,7 +383,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setDeclinedThisVersion:(BOOL)declined { - (void)setDeclinedThisVersion:(BOOL)declined {
[[NSUserDefaults standardUserDefaults] setObject:(declined ? self.applicationVersion : nil) [[NSUserDefaults standardUserDefaults] setObject:(declined ? self.applicationVersion : nil)
forKey:iRateDeclinedVersionKey]; forKey:iRateDeclinedVersionKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (BOOL)declinedAnyVersion { - (BOOL)declinedAnyVersion {
@ -395,7 +401,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setRatedThisVersion:(BOOL)rated { - (void)setRatedThisVersion:(BOOL)rated {
[[NSUserDefaults standardUserDefaults] setObject:(rated ? self.applicationVersion : nil) [[NSUserDefaults standardUserDefaults] setObject:(rated ? self.applicationVersion : nil)
forKey:iRateRatedVersionKey]; forKey:iRateRatedVersionKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (BOOL)ratedAnyVersion { - (BOOL)ratedAnyVersion {
@ -584,7 +590,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
- (void)setAppStoreIDOnMainThread:(NSString *)appStoreIDString { - (void)setAppStoreIDOnMainThread:(NSString *)appStoreIDString {
_appStoreID = [appStoreIDString integerValue]; _appStoreID = [appStoreIDString integerValue];
[[NSUserDefaults standardUserDefaults] setInteger:_appStoreID forKey:iRateAppStoreIDKey]; [[NSUserDefaults standardUserDefaults] setInteger:_appStoreID forKey:iRateAppStoreIDKey];
[[NSUserDefaults standardUserDefaults] synchronize]; [self synchronizeWhenSafeToDoSo];
} }
- (void)connectionSucceeded { - (void)connectionSucceeded {
@ -924,7 +930,7 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
[defaults setInteger:0 forKey:iRateUseCountKey]; [defaults setInteger:0 forKey:iRateUseCountKey];
[defaults setInteger:0 forKey:iRateEventCountKey]; [defaults setInteger:0 forKey:iRateEventCountKey];
[defaults setObject:nil forKey:iRateLastRemindedKey]; [defaults setObject:nil forKey:iRateLastRemindedKey];
[defaults synchronize]; [self synchronizeWhenSafeToDoSo];
} else if ([[NSDate date] timeIntervalSinceDate:self.firstUsed] > } else if ([[NSDate date] timeIntervalSinceDate:self.firstUsed] >
(self.daysUntilPrompt - 1) * SECONDS_IN_A_DAY) { (self.daysUntilPrompt - 1) * SECONDS_IN_A_DAY) {
// if was previously installed, but we haven't yet prompted for a rating // if was previously installed, but we haven't yet prompted for a rating
@ -972,6 +978,26 @@ static NSString *const iRateMacAppStoreURLFormat = @"macappstore://itunes.apple
} }
} }
// Only synchronize when active.
- (void)synchronizeWhenSafeToDoSo
{
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
self.hasQueuedSynchronize = YES;
return;
}
[[NSUserDefaults standardUserDefaults] synchronize];
self.hasQueuedSynchronize = NO;
}
// Only synchronize when active.
- (void)applicationDidBecomeActive
{
if (self.hasQueuedSynchronize) {
[[NSUserDefaults standardUserDefaults] synchronize];
self.hasQueuedSynchronize = NO;
}
}
- (void)openRatingsPageInAppStore { - (void)openRatingsPageInAppStore {
if (!_ratingsURL && !self.appStoreID) { if (!_ratingsURL && !self.appStoreID) {
self.checkingForAppStoreID = YES; self.checkingForAppStoreID = YES;

Loading…
Cancel
Save