Skip to content
Browse files

Add landscape support

Show only two buttons in rate request dialog: 'Rate' and one of
'Reminde me' and 'No'. Use LandscapeHideCancelCount in Appirater.plist
to define how many times to show the 'Remind me' button before
showing the 'No' button.
  • Loading branch information...
1 parent 0632493 commit f275683952f9d8084714568941bc7771ee09b612 @jlopez committed Aug 28, 2012
Showing with 53 additions and 25 deletions.
  1. +8 −0 Appirater.h
  2. +43 −25 Appirater.m
  3. +2 −0 Appirater.plist.sample
View
8 Appirater.h
@@ -125,6 +125,14 @@ extern NSString *const kAppiraterReminderRequestDate;
#define APPIRATER_TIME_BEFORE_REMINDING 1 // double
/*
+ Due to screen dimension limitations, only one of the 'Remind me later' or
+ the 'No, thanks' button may be shown. This setting specifies how many times
+ the 'Remind me later' button should be shown before switching to the 'No thanks'
+ button. This setting does not have any effect while in portrait mode.
+ */
+#define APPIRATER_LANDSCAPE_HIDE_CANCEL_COUNT 5 // integer
+
+/*
'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.
*/
View
68 Appirater.m
@@ -45,6 +45,7 @@
NSString *const kAppiraterRatedCurrentVersion = @"kAppiraterRatedCurrentVersion";
NSString *const kAppiraterDeclinedToRate = @"kAppiraterDeclinedToRate";
NSString *const kAppiraterReminderRequestDate = @"kAppiraterReminderRequestDate";
+NSString *const kAppiraterDialogCount = @"kAppiraterDialogCount";
NSString *templateReviewURL = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@";
@@ -59,6 +60,7 @@
NSString *const kConfigUsesUntilPrompt = @"UsesUntilPrompt";
NSString *const kConfigSigEventsUntilPrompt = @"SigEventsUntilPrompt";
NSString *const kConfigTimeBeforeReminding = @"TimeBeforeReminding";
+NSString *const kConfigLandscapeHideCancelCount = @"LandscapeHideCancelCount";
NSString *const kConfigDebug = @"Debug";
@interface Appirater () {
@@ -101,6 +103,7 @@ - (id)init {
[defaults setObject:[NSNumber numberWithInteger:APPIRATER_USES_UNTIL_PROMPT] forKey:kConfigUsesUntilPrompt];
[defaults setObject:[NSNumber numberWithInteger:APPIRATER_SIG_EVENTS_UNTIL_PROMPT] forKey:kConfigSigEventsUntilPrompt];
[defaults setObject:[NSNumber numberWithInteger:APPIRATER_TIME_BEFORE_REMINDING] forKey:kConfigTimeBeforeReminding];
+ [defaults setObject:[NSNumber numberWithInteger:APPIRATER_LANDSCAPE_HIDE_CANCEL_COUNT] forKey:kConfigLandscapeHideCancelCount];
[defaults setObject:[NSNumber numberWithBool:APPIRATER_DEBUG] forKey:kConfigDebug];
NSString *path = [bundle pathForResource:@"Appirater" ofType:@"plist"];
@@ -186,11 +189,32 @@ + (Appirater*)sharedInstance {
}
- (void)showRatingAlert {
+ // Increment dialog count
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSInteger count = [defaults integerForKey:kAppiraterDialogCount] + 1;
+ [defaults setInteger:count forKey:kAppiraterDialogCount];
+ [defaults synchronize];
+
+ // Hide one of cancel/reminder button if in landscape mode
+ NSString *cancelButtonTitle = [self configurationStringForKey:kConfigCancelButton];
+ NSString *reminderButtonTitle = [self configurationStringForKey:kConfigRateLater];
+ UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
+ BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
+ if (isLandscape) {
+ if (count <= [self configurationIntegerForKey:kConfigLandscapeHideCancelCount])
+ cancelButtonTitle = nil;
+ else
+ reminderButtonTitle = nil;
+ }
+
+ if (debug)
+ NSLog(@"APPIRATER Show dialog. Count=%d Orientation=%d Landscape=%d", count, orientation, isLandscape);
+
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:[self configurationStringForKey:kConfigMessageTitle]
message:[self configurationStringForKey:kConfigMessage]
delegate:self
- cancelButtonTitle:[self configurationStringForKey:kConfigCancelButton]
- otherButtonTitles:[self configurationStringForKey:kConfigRateButton], [self configurationStringForKey:kConfigRateLater], nil] autorelease];
+ cancelButtonTitle:cancelButtonTitle
+ otherButtonTitles:[self configurationStringForKey:kConfigRateButton], reminderButtonTitle, nil] autorelease];
self.ratingAlert = alertView;
[alertView show];
}
@@ -278,8 +302,9 @@ - (void)incrementUseCount {
[userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion];
[userDefaults setBool:NO forKey:kAppiraterDeclinedToRate];
[userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate];
+ [userDefaults setInteger:0 forKey:kAppiraterDialogCount];
}
-
+
[userDefaults synchronize];
}
@@ -326,6 +351,7 @@ - (void)incrementSignificantEventCount {
[userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion];
[userDefaults setBool:NO forKey:kAppiraterDeclinedToRate];
[userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate];
+ [userDefaults setInteger:0 forKey:kAppiraterDialogCount];
}
[userDefaults synchronize];
@@ -412,28 +438,20 @@ + (void)rateApp {
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
-
- switch (buttonIndex) {
- case 0:
- {
- // they don't want to rate it
- [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
- [userDefaults synchronize];
- break;
- }
- case 1:
- {
- // they want to rate it
- [Appirater rateApp];
- break;
- }
- case 2:
- // remind them later
- [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
- [userDefaults synchronize];
- break;
- default:
- break;
+
+ if (buttonIndex == alertView.cancelButtonIndex) {
+ // they don't want to rate it
+ [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
+ [userDefaults synchronize];
+ }
+ else if (buttonIndex == alertView.firstOtherButtonIndex) {
+ // they want to rate it
+ [Appirater rateApp];
+ }
+ else if (buttonIndex == alertView.firstOtherButtonIndex + 1) {
+ // remind them later
+ [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
+ [userDefaults synchronize];
}
}
View
2 Appirater.plist.sample
@@ -27,6 +27,8 @@
<integer>-1</integer>
<key>TimeBeforeReminding</key>
<integer>1</integer>
+ <key>LandscapeHideCancelCount</key>
+ <integer>5</integer>
<key>Debug</key>
<false/>
</dict>

0 comments on commit f275683

Please sign in to comment.
Something went wrong with that request. Please try again.