From e51a0140c0ea60fac87d537a5d46c6eb347e1b2d Mon Sep 17 00:00:00 2001 From: Derek Johnson Date: Sat, 1 Apr 2017 12:12:09 -0700 Subject: [PATCH 1/2] Adds support for SKStoreReviewController with new flag Set useStoreReviewController to use the new review controller available in iOS 10.3+ --- iRate/iRate.h | 2 + iRate/iRate.m | 105 ++++++++++++++++++++++++++------------------------ 2 files changed, 56 insertions(+), 51 deletions(-) diff --git a/iRate/iRate.h b/iRate/iRate.h index ad5aaca5..0267668b 100644 --- a/iRate/iRate.h +++ b/iRate/iRate.h @@ -47,6 +47,7 @@ #import #if TARGET_OS_IPHONE #import +#import #define IRATE_EXTERN UIKIT_EXTERN #else #import @@ -128,6 +129,7 @@ typedef NS_ENUM(NSUInteger, iRateErrorCode) @property (nonatomic, assign) float daysUntilPrompt; @property (nonatomic, assign) float usesPerWeekForPrompt; @property (nonatomic, assign) float remindPeriod; +@property (nonatomic, assign) BOOL useStoreReviewController; //message text, you may wish to customise these @property (nonatomic, copy) NSString *messageTitle; diff --git a/iRate/iRate.m b/iRate/iRate.m index 642ba8a6..ce290378 100644 --- a/iRate/iRate.m +++ b/iRate/iRate.m @@ -851,70 +851,73 @@ - (void)promptForRating NSString *message = self.ratedAnyVersion? self.updateMessage: self.message; #if TARGET_OS_IPHONE - - UIViewController *topController = [UIApplication sharedApplication].delegate.window.rootViewController; - while (topController.presentedViewController) - { - topController = topController.presentedViewController; - } - - if ([UIAlertController class] && topController && self.useUIAlertControllerIfAvailable) - { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:self.messageTitle message:message preferredStyle:UIAlertControllerStyleAlert]; - - //rate action - [alert addAction:[UIAlertAction actionWithTitle:self.rateButtonLabel style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { - [self didDismissAlert:alert withButtonAtIndex:0]; - }]]; - - //cancel action - if ([self showCancelButton]) + float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue]; + if(self.useStoreReviewController && iOSVersion >= __IPHONE_10_3) { + [SKStoreReviewController requestReview]; + } else { + UIViewController *topController = [UIApplication sharedApplication].delegate.window.rootViewController; + while (topController.presentedViewController) { - [alert addAction:[UIAlertAction actionWithTitle:self.cancelButtonLabel style:UIAlertActionStyleCancel handler:^(__unused UIAlertAction *action) { - [self didDismissAlert:alert withButtonAtIndex:1]; - }]]; + topController = topController.presentedViewController; } - //remind action - if ([self showRemindButton]) + if ([UIAlertController class] && topController && self.useUIAlertControllerIfAvailable) { - [alert addAction:[UIAlertAction actionWithTitle:self.remindButtonLabel style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { - [self didDismissAlert:alert withButtonAtIndex:[self showCancelButton]? 2: 1]; + UIAlertController *alert = [UIAlertController alertControllerWithTitle:self.messageTitle message:message preferredStyle:UIAlertControllerStyleAlert]; + + //rate action + [alert addAction:[UIAlertAction actionWithTitle:self.rateButtonLabel style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { + [self didDismissAlert:alert withButtonAtIndex:0]; }]]; - } - self.visibleAlert = alert; + //cancel action + if ([self showCancelButton]) + { + [alert addAction:[UIAlertAction actionWithTitle:self.cancelButtonLabel style:UIAlertActionStyleCancel handler:^(__unused UIAlertAction *action) { + [self didDismissAlert:alert withButtonAtIndex:1]; + }]]; + } - //get current view controller and present alert - [topController presentViewController:alert animated:YES completion:NULL]; - } - else - { + //remind action + if ([self showRemindButton]) + { + [alert addAction:[UIAlertAction actionWithTitle:self.remindButtonLabel style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { + [self didDismissAlert:alert withButtonAtIndex:[self showCancelButton]? 2: 1]; + }]]; + } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.messageTitle - message:message - delegate:(id)self - cancelButtonTitle:nil - otherButtonTitles:self.rateButtonLabel, nil]; -#pragma clang diagnostic pop + self.visibleAlert = alert; - if ([self showCancelButton]) - { - [alert addButtonWithTitle:self.cancelButtonLabel]; - alert.cancelButtonIndex = 1; + //get current view controller and present alert + [topController presentViewController:alert animated:YES completion:NULL]; } - - if ([self showRemindButton]) + else { - [alert addButtonWithTitle:self.remindButtonLabel]; - } - self.visibleAlert = alert; - [self.visibleAlert show]; - } + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.messageTitle + message:message + delegate:(id)self + cancelButtonTitle:nil + otherButtonTitles:self.rateButtonLabel, nil]; + #pragma clang diagnostic pop + if ([self showCancelButton]) + { + [alert addButtonWithTitle:self.cancelButtonLabel]; + alert.cancelButtonIndex = 1; + } + + if ([self showRemindButton]) + { + [alert addButtonWithTitle:self.remindButtonLabel]; + } + + self.visibleAlert = alert; + [self.visibleAlert show]; + } + } #else //only show when main window is available From 0e5c4dfc4a6102879f4f57ce201734894a7b3a73 Mon Sep 17 00:00:00 2001 From: Derek Johnson Date: Sat, 1 Apr 2017 12:26:09 -0700 Subject: [PATCH 2/2] Adds support for SKStoreReviewController with new flag Set useStoreReviewController to use the new review controller available in iOS 10.3+ --- iRate/iRate.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iRate/iRate.m b/iRate/iRate.m index ce290378..6aad541d 100644 --- a/iRate/iRate.m +++ b/iRate/iRate.m @@ -92,6 +92,7 @@ #define IOS_7_0 7.0 #define IOS_7_1 7.1 +#define IOS_10_3 10.3 #define SECONDS_IN_A_DAY 86400.0 @@ -852,7 +853,7 @@ - (void)promptForRating #if TARGET_OS_IPHONE float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue]; - if(self.useStoreReviewController && iOSVersion >= __IPHONE_10_3) { + if(self.useStoreReviewController && iOSVersion >= IOS_10_3) { [SKStoreReviewController requestReview]; } else { UIViewController *topController = [UIApplication sharedApplication].delegate.window.rootViewController;