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

added userDidSignificantEvent method to handle weighted significant events #171

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
6 changes: 6 additions & 0 deletions Appirater.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ extern NSString *const kAppiraterReminderRequestDate;
*/
+ (void)userDidSignificantEvent:(BOOL)canPromptForRating;

/*!
Similar to +userDidSignificantEvent: but this method will increase the significant
event count by the quantity provided.
*/
+ (void)userDidSignificantEvent:(BOOL)canPromptForRating withQuantity:(NSInteger)quantity;

/*!
Tells Appirater to try and show the prompt (a rating alert). The prompt will be showed
if there is connection available, the user hasn't declined to rate
Expand Down
16 changes: 10 additions & 6 deletions Appirater.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ - (void)incrementUseCount {
[userDefaults synchronize];
}

- (void)incrementSignificantEventCount {
- (void)incrementSignificantEventCountWithQuantity:(NSInteger)quantity {
// get the app's version
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];

Expand Down Expand Up @@ -357,7 +357,7 @@ - (void)incrementSignificantEventCount {

// increment the significant event count
NSInteger sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount];
sigEventCount++;
sigEventCount += quantity;
[userDefaults setInteger:sigEventCount forKey:kAppiraterSignificantEventCount];
if (_debug)
NSLog(@"APPIRATER Significant event count: %@", @(sigEventCount));
Expand All @@ -368,7 +368,7 @@ - (void)incrementSignificantEventCount {
[userDefaults setObject:version forKey:kAppiraterCurrentVersion];
[userDefaults setDouble:0 forKey:kAppiraterFirstUseDate];
[userDefaults setInteger:0 forKey:kAppiraterUseCount];
[userDefaults setInteger:1 forKey:kAppiraterSignificantEventCount];
[userDefaults setInteger:quantity forKey:kAppiraterSignificantEventCount];
[userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion];
[userDefaults setBool:NO forKey:kAppiraterDeclinedToRate];
[userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate];
Expand All @@ -391,8 +391,8 @@ - (void)incrementAndRate:(BOOL)canPromptForRating {
}
}

- (void)incrementSignificantEventAndRate:(BOOL)canPromptForRating {
[self incrementSignificantEventCount];
- (void)incrementSignificantEventWithQuantity:(NSInteger)quantity andRate:(BOOL)canPromptForRating {
[self incrementSignificantEventCountWithQuantity:quantity];

if (canPromptForRating &&
[self ratingConditionsHaveBeenMet] &&
Expand Down Expand Up @@ -446,9 +446,13 @@ + (void)appEnteredForeground:(BOOL)canPromptForRating {
}

+ (void)userDidSignificantEvent:(BOOL)canPromptForRating {
[self userDidSignificantEvent:canPromptForRating withQuantity:1];
}

+ (void)userDidSignificantEvent:(BOOL)canPromptForRating withQuantity:(NSInteger)quantity {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
[[Appirater sharedInstance] incrementSignificantEventAndRate:canPromptForRating];
[[Appirater sharedInstance] incrementSignificantEventWithQuantity:quantity andRate:canPromptForRating];
});
}

Expand Down