Skip to content

Commit

Permalink
Merge pull request #50 from knokknok/master
Browse files Browse the repository at this point in the history
Add check for usage frequency
  • Loading branch information
nicklockwood committed Oct 6, 2012
2 parents 5d959c2 + f94600f commit 3315db7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions iRate/iRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ iRateErrorCode;
NSUInteger _usesUntilPrompt;
NSUInteger _eventsUntilPrompt;
float _daysUntilPrompt;
float _usageFrequencyForPrompt;
float _remindPeriod;
NSString *_messageTitle;
NSString *_message;
Expand Down Expand Up @@ -165,6 +166,7 @@ iRateErrorCode;
@property (nonatomic, assign) NSUInteger usesUntilPrompt;
@property (nonatomic, assign) NSUInteger eventsUntilPrompt;
@property (nonatomic, assign) float daysUntilPrompt;
@property (nonatomic, assign) float usageFrequencyForPrompt;
@property (nonatomic, assign) float remindPeriod;

//message text, you may wish to customise these, e.g. for localisation
Expand Down
13 changes: 13 additions & 0 deletions iRate/iRate.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ @implementation iRate
@synthesize applicationVersion = _applicationVersion;
@synthesize applicationBundleID = _applicationBundleID;
@synthesize daysUntilPrompt = _daysUntilPrompt;
@synthesize usageFrequencyForPrompt = _usageFrequencyForPrompt;
@synthesize usesUntilPrompt = _usesUntilPrompt;
@synthesize eventsUntilPrompt = _eventsUntilPrompt;
@synthesize remindPeriod = _remindPeriod;
Expand Down Expand Up @@ -200,6 +201,7 @@ - (iRate *)init
self.usesUntilPrompt = 10;
self.eventsUntilPrompt = 10;
self.daysUntilPrompt = 10.0f;
self.usageFrequencyForPrompt = 0.0f;
self.remindPeriod = 1.0f;
self.verboseLogging = NO;
self.previewMode = NO;
Expand Down Expand Up @@ -469,6 +471,17 @@ - (BOOL)shouldPromptForRating
return NO;
}

//check if usage frequency is high enough
else if ((float)self.usesCount < self.usageFrequencyForPrompt * [[NSDate date] timeIntervalSinceDate:self.firstUsed] / (7 * SECONDS_IN_A_DAY))
{
if (self.verboseLogging)
{
NSLog(@"iRate did not prompt for rating because the app has only been used %i times in %g weeks",
(int)self.usesCount, [[NSDate date] timeIntervalSinceDate:self.firstUsed] / (7 * SECONDS_IN_A_DAY));
}
return NO;
}

//check if within the reminder period
else if (self.lastReminded != nil && [[NSDate date] timeIntervalSinceDate:self.lastReminded] < self.remindPeriod * SECONDS_IN_A_DAY)
{
Expand Down

0 comments on commit 3315db7

Please sign in to comment.