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

Add support for SKStoreReviewController for iOS 10.3+ #283

Merged
merged 2 commits into from
Jun 4, 2017
Merged
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
2 changes: 2 additions & 0 deletions iRate/iRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#define IRATE_EXTERN UIKIT_EXTERN
#else
#import <Cocoa/Cocoa.h>
Expand Down Expand Up @@ -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;
Expand Down
106 changes: 55 additions & 51 deletions iRate/iRate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -851,70 +852,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 >= IOS_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<UIAlertViewDelegate>)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<UIAlertViewDelegate>)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
Expand Down