Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix off by one bug, and added reset method, and refactored debug mode #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Appirater.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,21 @@ extern NSString *const kAppiraterReminderRequestDate;
*/
+ (void) setTimeBeforeReminding:(double)value;

/*
'YES' will show the Appirater logs. Useful for debugging.
*/
+ (void) setDebug:(BOOL)debug;

/*
'YES' will show the Appirater alert everytime. Useful for testing how your message
looks and making sure the link to your app's review page works.
*/
+ (void) setDebug:(BOOL)debug;
+ (void)setForceRatingConditionsMet:(BOOL)forceRatingConditionsMet;

/*
Tells Appirater to reset all counters
*/
+ (void)reset;

/*
Set the delegate if you want to know when Appirater does something
Expand Down
26 changes: 23 additions & 3 deletions Appirater.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
static NSInteger _significantEventsUntilPrompt = -1;
static double _timeBeforeReminding = 1;
static BOOL _debug = NO;
static BOOL _forceRatingConditionsMet = NO;
static id<AppiraterDelegate> _delegate;
static BOOL _usesAnimation = TRUE;
static BOOL _openInAppStore = NO;
Expand Down Expand Up @@ -100,6 +101,25 @@ + (void) setTimeBeforeReminding:(double)value {
+ (void) setDebug:(BOOL)debug {
_debug = debug;
}

+ (void) setForceRatingConditionsMet:(BOOL)forceRatingConditionsMet {
_forceRatingConditionsMet = forceRatingConditionsMet;
}

+ (void) reset {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

[userDefaults removeObjectForKey:kAppiraterCurrentVersion];
[userDefaults removeObjectForKey:kAppiraterFirstUseDate];
[userDefaults removeObjectForKey:kAppiraterUseCount];
[userDefaults removeObjectForKey:kAppiraterSignificantEventCount];
[userDefaults removeObjectForKey:kAppiraterRatedCurrentVersion];
[userDefaults removeObjectForKey:kAppiraterDeclinedToRate];
[userDefaults removeObjectForKey:kAppiraterReminderRequestDate];

[userDefaults synchronize];
}

+ (void)setDelegate:(id<AppiraterDelegate>)delegate{
_delegate = delegate;
}
Expand Down Expand Up @@ -178,7 +198,7 @@ - (void)showRatingAlert {
}

- (BOOL)ratingConditionsHaveBeenMet {
if (_debug)
if (_forceRatingConditionsMet)
return YES;

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
Expand All @@ -191,12 +211,12 @@ - (BOOL)ratingConditionsHaveBeenMet {

// check if the app has been used enough
int useCount = [userDefaults integerForKey:kAppiraterUseCount];
if (useCount <= _usesUntilPrompt)
if (useCount < _usesUntilPrompt)
return NO;

// check if the user has done enough significant events
int sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount];
if (sigEventCount <= _significantEventsUntilPrompt)
if (sigEventCount < _significantEventsUntilPrompt)
return NO;

// has the user previously declined to rate this version of the app?
Expand Down