Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit f275683952f9d8084714568941bc7771ee09b612 1 parent 0632493
Jesus Lopez authored

Showing 3 changed files with 53 additions and 25 deletions. Show diff stats Hide diff stats

  1. +8 0 Appirater.h
  2. +43 25 Appirater.m
  3. +2 0  Appirater.plist.sample
8 Appirater.h
@@ -125,6 +125,14 @@ extern NSString *const kAppiraterReminderRequestDate;
125 125 #define APPIRATER_TIME_BEFORE_REMINDING 1 // double
126 126
127 127 /*
  128 + Due to screen dimension limitations, only one of the 'Remind me later' or
  129 + the 'No, thanks' button may be shown. This setting specifies how many times
  130 + the 'Remind me later' button should be shown before switching to the 'No thanks'
  131 + button. This setting does not have any effect while in portrait mode.
  132 + */
  133 +#define APPIRATER_LANDSCAPE_HIDE_CANCEL_COUNT 5 // integer
  134 +
  135 +/*
128 136 'YES' will show the Appirater alert everytime. Useful for testing how your message
129 137 looks and making sure the link to your app's review page works.
130 138 */
68 Appirater.m
@@ -45,6 +45,7 @@
45 45 NSString *const kAppiraterRatedCurrentVersion = @"kAppiraterRatedCurrentVersion";
46 46 NSString *const kAppiraterDeclinedToRate = @"kAppiraterDeclinedToRate";
47 47 NSString *const kAppiraterReminderRequestDate = @"kAppiraterReminderRequestDate";
  48 +NSString *const kAppiraterDialogCount = @"kAppiraterDialogCount";
48 49
49 50 NSString *templateReviewURL = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@";
50 51
@@ -59,6 +60,7 @@
59 60 NSString *const kConfigUsesUntilPrompt = @"UsesUntilPrompt";
60 61 NSString *const kConfigSigEventsUntilPrompt = @"SigEventsUntilPrompt";
61 62 NSString *const kConfigTimeBeforeReminding = @"TimeBeforeReminding";
  63 +NSString *const kConfigLandscapeHideCancelCount = @"LandscapeHideCancelCount";
62 64 NSString *const kConfigDebug = @"Debug";
63 65
64 66 @interface Appirater () {
@@ -101,6 +103,7 @@ - (id)init {
101 103 [defaults setObject:[NSNumber numberWithInteger:APPIRATER_USES_UNTIL_PROMPT] forKey:kConfigUsesUntilPrompt];
102 104 [defaults setObject:[NSNumber numberWithInteger:APPIRATER_SIG_EVENTS_UNTIL_PROMPT] forKey:kConfigSigEventsUntilPrompt];
103 105 [defaults setObject:[NSNumber numberWithInteger:APPIRATER_TIME_BEFORE_REMINDING] forKey:kConfigTimeBeforeReminding];
  106 + [defaults setObject:[NSNumber numberWithInteger:APPIRATER_LANDSCAPE_HIDE_CANCEL_COUNT] forKey:kConfigLandscapeHideCancelCount];
104 107 [defaults setObject:[NSNumber numberWithBool:APPIRATER_DEBUG] forKey:kConfigDebug];
105 108
106 109 NSString *path = [bundle pathForResource:@"Appirater" ofType:@"plist"];
@@ -186,11 +189,32 @@ + (Appirater*)sharedInstance {
186 189 }
187 190
188 191 - (void)showRatingAlert {
  192 + // Increment dialog count
  193 + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  194 + NSInteger count = [defaults integerForKey:kAppiraterDialogCount] + 1;
  195 + [defaults setInteger:count forKey:kAppiraterDialogCount];
  196 + [defaults synchronize];
  197 +
  198 + // Hide one of cancel/reminder button if in landscape mode
  199 + NSString *cancelButtonTitle = [self configurationStringForKey:kConfigCancelButton];
  200 + NSString *reminderButtonTitle = [self configurationStringForKey:kConfigRateLater];
  201 + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  202 + BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
  203 + if (isLandscape) {
  204 + if (count <= [self configurationIntegerForKey:kConfigLandscapeHideCancelCount])
  205 + cancelButtonTitle = nil;
  206 + else
  207 + reminderButtonTitle = nil;
  208 + }
  209 +
  210 + if (debug)
  211 + NSLog(@"APPIRATER Show dialog. Count=%d Orientation=%d Landscape=%d", count, orientation, isLandscape);
  212 +
189 213 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:[self configurationStringForKey:kConfigMessageTitle]
190 214 message:[self configurationStringForKey:kConfigMessage]
191 215 delegate:self
192   - cancelButtonTitle:[self configurationStringForKey:kConfigCancelButton]
193   - otherButtonTitles:[self configurationStringForKey:kConfigRateButton], [self configurationStringForKey:kConfigRateLater], nil] autorelease];
  216 + cancelButtonTitle:cancelButtonTitle
  217 + otherButtonTitles:[self configurationStringForKey:kConfigRateButton], reminderButtonTitle, nil] autorelease];
194 218 self.ratingAlert = alertView;
195 219 [alertView show];
196 220 }
@@ -278,8 +302,9 @@ - (void)incrementUseCount {
278 302 [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion];
279 303 [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate];
280 304 [userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate];
  305 + [userDefaults setInteger:0 forKey:kAppiraterDialogCount];
281 306 }
282   -
  307 +
283 308 [userDefaults synchronize];
284 309 }
285 310
@@ -326,6 +351,7 @@ - (void)incrementSignificantEventCount {
326 351 [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion];
327 352 [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate];
328 353 [userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate];
  354 + [userDefaults setInteger:0 forKey:kAppiraterDialogCount];
329 355 }
330 356
331 357 [userDefaults synchronize];
@@ -412,28 +438,20 @@ + (void)rateApp {
412 438
413 439 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
414 440 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
415   -
416   - switch (buttonIndex) {
417   - case 0:
418   - {
419   - // they don't want to rate it
420   - [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
421   - [userDefaults synchronize];
422   - break;
423   - }
424   - case 1:
425   - {
426   - // they want to rate it
427   - [Appirater rateApp];
428   - break;
429   - }
430   - case 2:
431   - // remind them later
432   - [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
433   - [userDefaults synchronize];
434   - break;
435   - default:
436   - break;
  441 +
  442 + if (buttonIndex == alertView.cancelButtonIndex) {
  443 + // they don't want to rate it
  444 + [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
  445 + [userDefaults synchronize];
  446 + }
  447 + else if (buttonIndex == alertView.firstOtherButtonIndex) {
  448 + // they want to rate it
  449 + [Appirater rateApp];
  450 + }
  451 + else if (buttonIndex == alertView.firstOtherButtonIndex + 1) {
  452 + // remind them later
  453 + [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
  454 + [userDefaults synchronize];
437 455 }
438 456 }
439 457
2  Appirater.plist.sample
@@ -27,6 +27,8 @@
27 27 <integer>-1</integer>
28 28 <key>TimeBeforeReminding</key>
29 29 <integer>1</integer>
  30 + <key>LandscapeHideCancelCount</key>
  31 + <integer>5</integer>
30 32 <key>Debug</key>
31 33 <false/>
32 34 </dict>

0 comments on commit f275683

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