diff --git a/Appirater.h b/Appirater.h index b0d5f582..f556b370 100644 --- a/Appirater.h +++ b/Appirater.h @@ -35,8 +35,8 @@ */ #import -#import "AppiraterDelegate.h" #import +#import "AppiraterDelegate.h" extern NSString *const kAppiraterFirstUseDate; extern NSString *const kAppiraterUseCount; @@ -57,7 +57,20 @@ extern NSString *const kAppiraterReminderRequestDate; #define APPIRATER_APP_NAME APPIRATER_LOCALIZED_APP_NAME ? APPIRATER_LOCALIZED_APP_NAME : [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] /*! - This is the message your users will see once they've passed the day+launches + This is first message your users will see once they've passed the day+launches + threshold. + */ +#define APPIRATER_LOCALIZED_PRELIMINARY_MESSAGE_TITLE NSLocalizedStringFromTableInBundle(@"%@", @"AppiraterLocalizable", [Appirater bundle], nil) +#define APPIRATER_PRELIMINARY_MESSAGE_TITLE [NSString stringWithFormat:APPIRATER_LOCALIZED_PRELIMINARY_MESSAGE_TITLE, APPIRATER_APP_NAME] + +#define APPIRATER_LOCALIZED_PRELIMINARY_MESSAGE NSLocalizedStringFromTableInBundle(@"Are you enjoying %@?", @"AppiraterLocalizable", [Appirater bundle], nil) +#define APPIRATER_PRELIMINARY_MESSAGE [NSString stringWithFormat:APPIRATER_LOCALIZED_PRELIMINARY_MESSAGE, APPIRATER_APP_NAME] + +#define APPIRATER_PRELIMINARY_MESSAGE_YES_BUTTON NSLocalizedStringFromTableInBundle(@"Yes", @"AppiraterLocalizable", [Appirater bundle], nil) +#define APPIRATER_PRELIMINARY_MESSAGE_NO_BUTTON NSLocalizedStringFromTableInBundle(@"No", @"AppiraterLocalizable", [Appirater bundle], nil) + +/*! + This is the message your users will see once they've seen the first message threshold. */ #define APPIRATER_LOCALIZED_MESSAGE NSLocalizedStringFromTableInBundle(@"If you enjoy using %@, would you mind taking a moment to rate it? It won't take more than a minute. Thanks for your support!", @"AppiraterLocalizable", [Appirater bundle], nil) @@ -86,11 +99,16 @@ extern NSString *const kAppiraterReminderRequestDate; #define APPIRATER_RATE_LATER NSLocalizedStringFromTableInBundle(@"Remind me later", @"AppiraterLocalizable", [Appirater bundle], nil) @interface Appirater : NSObject { - +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" UIAlertView *ratingAlert; +#pragma clang diagnostic pop } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" @property(nonatomic, strong) UIAlertView *ratingAlert; +#pragma clang diagnostic pop @property(nonatomic) BOOL openInAppStore; #if __has_feature(objc_arc_weak) @property(nonatomic, weak) NSObject *delegate; @@ -191,6 +209,11 @@ extern NSString *const kAppiraterReminderRequestDate; */ + (void) setAppId:(NSString*)appId; +/*! + Users will see a preliminary message before asked to rate the app. + */ ++ (void) setShowPreliminaryMessage:(BOOL)showPreliminaryMessage; + /*! Users will need to have the same version of your app installed for this many days before they will be prompted to rate it. @@ -281,7 +304,7 @@ extern NSString *const kAppiraterReminderRequestDate; Calls [Appirater appLaunched:YES]. See appLaunched: for details of functionality. */ -+ (void)appLaunched __attribute__((deprecated)); ++ (void)appLaunched; /*! DEPRECATED: While still functional, it's better to use @@ -289,6 +312,6 @@ extern NSString *const kAppiraterReminderRequestDate; Calls [Appirater tryToShowPrompt]. See tryToShowPrompt for details of functionality. */ -+ (void)showPrompt __attribute__((deprecated)); ++ (void)showPrompt; @end diff --git a/Appirater.m b/Appirater.m index bceaf2ad..edf8e862 100644 --- a/Appirater.m +++ b/Appirater.m @@ -34,8 +34,9 @@ * Copyright 2012 Arash Payan. All rights reserved. */ +#import +#import #import "Appirater.h" -#import #include #if ! __has_feature(objc_arc) @@ -46,14 +47,28 @@ NSString *const kAppiraterUseCount = @"kAppiraterUseCount"; NSString *const kAppiraterSignificantEventCount = @"kAppiraterSignificantEventCount"; NSString *const kAppiraterCurrentVersion = @"kAppiraterCurrentVersion"; -NSString *const kAppiraterRatedCurrentVersion = @"kAppiraterRatedCurrentVersion"; +NSString *const kAppiraterRated = @"kAppiraterRated"; NSString *const kAppiraterDeclinedToRate = @"kAppiraterDeclinedToRate"; NSString *const kAppiraterReminderRequestDate = @"kAppiraterReminderRequestDate"; NSString *templateReviewURL = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID"; NSString *templateReviewURLiOS7 = @"itms-apps://itunes.apple.com/app/idAPP_ID"; +static const NSInteger AlertButtonIndexInvalid = -1; + +typedef NS_ENUM(NSInteger, PreliminaryAlertButtonIndex) { + PreliminaryAlertButtonNo = 0, + PreliminaryAlertButtonYes +}; + +typedef NS_ENUM(NSInteger, RateAlertButtonIndex) { + RateAlertButtonIndexDontRate = 0, + RateAlertButtonIndexRateNow, + RateAlertButtonIndexRateLater +}; + static NSString *_appId; +static BOOL _showPreliminaryMessage = NO; static double _daysUntilPrompt = 30; static NSInteger _usesUntilPrompt = 20; static NSInteger _significantEventsUntilPrompt = -1; @@ -64,21 +79,18 @@ #else __weak static id _delegate; #endif -static BOOL _usesAnimation = TRUE; +static BOOL _usesAnimation = YES; static UIStatusBarStyle _statusBarStyle; -static BOOL _modalOpen = false; +static BOOL _modalOpen = NO; static BOOL _alwaysUseMainBundle = NO; -@interface Appirater () -- (BOOL)connectedToNetwork; -+ (Appirater*)sharedInstance; -- (void)showPromptWithChecks:(BOOL)withChecks - displayRateLaterButton:(BOOL)displayRateLaterButton; -- (void)showRatingAlert:(BOOL)displayRateLaterButton; -- (void)showRatingAlert; -- (BOOL)ratingConditionsHaveBeenMet; -- (void)incrementUseCount; -- (void)hideRatingAlert; +static const NSInteger kPreliminaryAlertViewTag = 1000; +static const NSInteger kRateAlertViewTag = 1001; + +@interface Appirater () { + BOOL _shouldShowRateLaterButton; +} + @end @implementation Appirater @@ -89,6 +101,10 @@ + (void) setAppId:(NSString *)appId { _appId = appId; } ++ (void) setShowPreliminaryMessage:(BOOL)showPreliminaryMessage { + _showPreliminaryMessage = showPreliminaryMessage; +} + + (void) setDaysUntilPrompt:(double)value { _daysUntilPrompt = value; } @@ -175,12 +191,14 @@ - (BOOL)connectedToNetwork { SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); SCNetworkReachabilityFlags flags; - BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); + BOOL didRetrieveFlags = (BOOL)SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); CFRelease(defaultRouteReachability); if (!didRetrieveFlags) { - NSLog(@"Error. Could not recover network reachability flags"); + if (_debug) { + NSLog(@"Error. Could not recover network reachability flags"); + } return NO; } @@ -189,10 +207,17 @@ - (BOOL)connectedToNetwork { BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection; NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"]; - NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; - NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:self]; - return ((isReachable && !needsConnection) || nonWiFi) ? (testConnection ? YES : NO) : NO; + NSURLSessionConfiguration* sessionConfiguration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; + sessionConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; + sessionConfiguration.timeoutIntervalForRequest = 20.0; + + NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration]; + + NSURLSessionTask *task = [session dataTaskWithURL:testURL]; + [task resume]; + + return ((isReachable && !needsConnection) || nonWiFi) ? ( (task.state != NSURLSessionTaskStateSuspended) ? YES : NO ) : NO; } + (Appirater*)sharedInstance { @@ -212,33 +237,73 @@ + (Appirater*)sharedInstance { } - (void)showRatingAlert:(BOOL)displayRateLaterButton { - UIAlertView *alertView = nil; - if (displayRateLaterButton) { - alertView = [[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE - message:APPIRATER_MESSAGE - delegate:self - cancelButtonTitle:APPIRATER_CANCEL_BUTTON - otherButtonTitles:APPIRATER_RATE_BUTTON, APPIRATER_RATE_LATER, nil]; - } else { - alertView = [[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE - message:APPIRATER_MESSAGE - delegate:self - cancelButtonTitle:APPIRATER_CANCEL_BUTTON - otherButtonTitles:APPIRATER_RATE_BUTTON, nil]; - } + if (_showPreliminaryMessage) { + _shouldShowRateLaterButton = displayRateLaterButton; + [self reallyShowPreliminaryAlert]; + } else { + [self reallyShowRatingAlert:displayRateLaterButton]; + } +} +- (void)showRatingAlert +{ + [self showRatingAlert:YES]; +} + +- (void)reallyShowPreliminaryAlert { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:APPIRATER_PRELIMINARY_MESSAGE_TITLE +#pragma clang diagnostic pop + message:APPIRATER_PRELIMINARY_MESSAGE + delegate:self + cancelButtonTitle:APPIRATER_PRELIMINARY_MESSAGE_NO_BUTTON + otherButtonTitles:APPIRATER_PRELIMINARY_MESSAGE_YES_BUTTON, nil]; + alertView.tag = kPreliminaryAlertViewTag; + self.ratingAlert = alertView; [alertView show]; - + id delegate = _delegate; - if (delegate && [delegate respondsToSelector:@selector(appiraterDidDisplayAlert:)]) { - [delegate appiraterDidDisplayAlert:self]; + if (delegate && [delegate respondsToSelector:@selector(appiraterDidDisplayPreliminaryAlert:)]) { + [delegate appiraterDidDisplayPreliminaryAlert:self]; } } -- (void)showRatingAlert -{ - [self showRatingAlert:true]; +- (void)reallyShowRatingAlert:(BOOL)displayRateLaterButton { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + UIAlertView *alertView = nil; +#pragma clang diagnostic pop + if (displayRateLaterButton) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + alertView = [[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE +#pragma clang diagnostic pop + message:APPIRATER_MESSAGE + delegate:self + cancelButtonTitle:APPIRATER_CANCEL_BUTTON + otherButtonTitles:APPIRATER_RATE_BUTTON, APPIRATER_RATE_LATER, nil]; + } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + alertView = [[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE +#pragma clang diagnostic pop + message:APPIRATER_MESSAGE + delegate:self + cancelButtonTitle:APPIRATER_CANCEL_BUTTON + otherButtonTitles:APPIRATER_RATE_BUTTON, nil]; + } + + alertView.tag = kRateAlertViewTag; + + self.ratingAlert = alertView; + [alertView show]; + + id delegate = _delegate; + if (delegate && [delegate respondsToSelector:@selector(appiraterDidDisplayAlert:)]) { + [delegate appiraterDidDisplayAlert:self]; + } } - (BOOL)ratingConditionsHaveBeenMet { @@ -268,7 +333,7 @@ - (BOOL)ratingConditionsHaveBeenMet { return NO; // has the user already rated the app? - if ([self userHasRatedCurrentVersion]) + if ([self userHasRatedApp]) return NO; // if the user wanted to be reminded later, has enough time passed? @@ -292,40 +357,32 @@ - (void)incrementUseCount { { trackingVersion = version; [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; - } - - if (_debug) - NSLog(@"APPIRATER Tracking version: %@", trackingVersion); - - if ([trackingVersion isEqualToString:version]) - { - // check if the first use date has been set. if not, set it. - NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterFirstUseDate]; - if (timeInterval == 0) - { - timeInterval = [[NSDate date] timeIntervalSince1970]; - [userDefaults setDouble:timeInterval forKey:kAppiraterFirstUseDate]; - } - - // increment the use count - NSInteger useCount = [userDefaults integerForKey:kAppiraterUseCount]; - useCount++; - [userDefaults setInteger:useCount forKey:kAppiraterUseCount]; - if (_debug) - NSLog(@"APPIRATER Use count: %@", @(useCount)); - } - else - { - // it's a new version of the app, so restart tracking - [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterFirstUseDate]; - [userDefaults setInteger:1 forKey:kAppiraterUseCount]; + [userDefaults setInteger:0 forKey:kAppiraterUseCount]; [userDefaults setInteger:0 forKey:kAppiraterSignificantEventCount]; - [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion]; + [userDefaults setBool:NO forKey:kAppiraterRated]; [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate]; [userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate]; } + if (_debug) + NSLog(@"APPIRATER Tracking version: %@", trackingVersion); + + // check if the first use date has been set. if not, set it. + NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterFirstUseDate]; + if (timeInterval == 0) + { + timeInterval = [[NSDate date] timeIntervalSince1970]; + [userDefaults setDouble:timeInterval forKey:kAppiraterFirstUseDate]; + } + + // increment the use count + NSInteger useCount = [userDefaults integerForKey:kAppiraterUseCount]; + useCount++; + [userDefaults setInteger:useCount forKey:kAppiraterUseCount]; + if (_debug) + NSLog(@"APPIRATER Use count: %@", @(useCount)); + [userDefaults synchronize]; } @@ -340,40 +397,33 @@ - (void)incrementSignificantEventCount { { trackingVersion = version; [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; - } - - if (_debug) - NSLog(@"APPIRATER Tracking version: %@", trackingVersion); - - if ([trackingVersion isEqualToString:version]) - { - // check if the first use date has been set. if not, set it. - NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterFirstUseDate]; - if (timeInterval == 0) - { - timeInterval = [[NSDate date] timeIntervalSince1970]; - [userDefaults setDouble:timeInterval forKey:kAppiraterFirstUseDate]; - } - - // increment the significant event count - NSInteger sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount]; - sigEventCount++; - [userDefaults setInteger:sigEventCount forKey:kAppiraterSignificantEventCount]; - if (_debug) - NSLog(@"APPIRATER Significant event count: %@", @(sigEventCount)); - } - else - { - // it's a new version of the app, so restart tracking - [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; [userDefaults setDouble:0 forKey:kAppiraterFirstUseDate]; [userDefaults setInteger:0 forKey:kAppiraterUseCount]; - [userDefaults setInteger:1 forKey:kAppiraterSignificantEventCount]; - [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion]; + [userDefaults setInteger:0 forKey:kAppiraterSignificantEventCount]; + [userDefaults setBool:NO forKey:kAppiraterRated]; [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate]; [userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate]; } + if (_debug) + NSLog(@"APPIRATER Tracking version: %@", trackingVersion); + + // check if the first use date has been set. if not, set it. + NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterFirstUseDate]; + if (timeInterval == 0) + { + timeInterval = [[NSDate date] timeIntervalSince1970]; + [userDefaults setDouble:timeInterval forKey:kAppiraterFirstUseDate]; + } + + // increment the significant event count + NSInteger sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount]; + sigEventCount++; + [userDefaults setInteger:sigEventCount forKey:kAppiraterSignificantEventCount]; + + if (_debug) + NSLog(@"APPIRATER Significant event count: %@", @(sigEventCount)); + [userDefaults synchronize]; } @@ -409,8 +459,8 @@ - (BOOL)userHasDeclinedToRate { return [[NSUserDefaults standardUserDefaults] boolForKey:kAppiraterDeclinedToRate]; } -- (BOOL)userHasRatedCurrentVersion { - return [[NSUserDefaults standardUserDefaults] boolForKey:kAppiraterRatedCurrentVersion]; +- (BOOL)userHasRatedApp { + return [[NSUserDefaults standardUserDefaults] boolForKey:kAppiraterRated]; } + (void)appLaunched { @@ -428,7 +478,7 @@ - (void)hideRatingAlert { if (self.ratingAlert.visible) { if (_debug) NSLog(@"APPIRATER Hiding Alert"); - [self.ratingAlert dismissWithClickedButtonIndex:-1 animated:NO]; + [self.ratingAlert dismissWithClickedButtonIndex:AlertButtonIndexInvalid animated:NO]; } } @@ -457,23 +507,24 @@ + (void)showPrompt { } + (void)tryToShowPrompt { - [[Appirater sharedInstance] showPromptWithChecks:true - displayRateLaterButton:true]; + [[Appirater sharedInstance] showPromptWithChecks:YES + displayRateLaterButton:YES]; } + (void)forceShowPrompt:(BOOL)displayRateLaterButton { - [[Appirater sharedInstance] showPromptWithChecks:false + [[Appirater sharedInstance] showPromptWithChecks:NO displayRateLaterButton:displayRateLaterButton]; } - (void)showPromptWithChecks:(BOOL)withChecks displayRateLaterButton:(BOOL)displayRateLaterButton { - bool showPrompt = true; + BOOL showPrompt = YES; if (withChecks) { - showPrompt = ([self connectedToNetwork] - && ![self userHasDeclinedToRate] - && ![self userHasRatedCurrentVersion]); - } + showPrompt = ([self connectedToNetwork] + && ![self userHasDeclinedToRate] + && ![self userHasRatedApp] + && [self ratingConditionsHaveBeenMet]); + } if (showPrompt) { [self showRatingAlert:displayRateLaterButton]; } @@ -519,14 +570,14 @@ + (UIViewController *) topMostViewController: (UIViewController *) controller { + (void)rateApp { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - [userDefaults setBool:YES forKey:kAppiraterRatedCurrentVersion]; + [userDefaults setBool:YES forKey:kAppiraterRated]; [userDefaults synchronize]; //Use the in-app StoreKit view if available (iOS 6) and imported. This works in the simulator. if (![Appirater sharedInstance].openInAppStore && NSStringFromClass([SKStoreProductViewController class]) != nil) { SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init]; - NSNumber *appId = [NSNumber numberWithInteger:_appId.integerValue]; + NSNumber *appId = @(_appId.integerValue); [storeViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:appId} completionBlock:nil]; storeViewController.delegate = self.sharedInstance; @@ -536,11 +587,6 @@ + (void)rateApp { } [[self getRootViewController] presentViewController:storeViewController animated:_usesAnimation completion:^{ [self setModalOpen:YES]; - //Temporarily use a black status bar to match the StoreKit view. - [self setStatusBarStyle:[UIApplication sharedApplication].statusBarStyle]; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:_usesAnimation]; -#endif }]; //Use the standard openUrl method if StoreKit is unavailable. @@ -556,47 +602,85 @@ + (void)rateApp { reviewURL = [templateReviewURLiOS7 stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%@", _appId]]; } - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]]; + [UIApplication.sharedApplication openURL:[NSURL URLWithString:reviewURL] + options:@{} + completionHandler:nil]; #endif } } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#pragma clang diagnostic ignored "-Wdeprecated-implementations" - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - +#pragma clang diagnostic push + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + id delegate = _delegate; - - switch (buttonIndex) { - case 0: - { - // they don't want to rate it - [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate]; - [userDefaults synchronize]; - if(delegate && [delegate respondsToSelector:@selector(appiraterDidDeclineToRate:)]){ - [delegate appiraterDidDeclineToRate:self]; - } - break; - } - case 1: - { - // they want to rate it - [Appirater rateApp]; - if(delegate&& [delegate respondsToSelector:@selector(appiraterDidOptToRate:)]){ - [delegate appiraterDidOptToRate:self]; - } - break; - } - case 2: - // remind them later - [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate]; - [userDefaults synchronize]; - if(delegate && [delegate respondsToSelector:@selector(appiraterDidOptToRemindLater:)]){ - [delegate appiraterDidOptToRemindLater:self]; - } - break; - default: - break; - } + + switch (alertView.tag) { + case kPreliminaryAlertViewTag: + { + switch (buttonIndex) { + case PreliminaryAlertButtonNo: + [self didDeclineToRate]; + + if ([delegate respondsToSelector:@selector(appiraterDidDeclinePreliminaryAlert:)]) { + [delegate appiraterDidDeclinePreliminaryAlert:self]; + } + + break; + case PreliminaryAlertButtonYes: + [self reallyShowRatingAlert:_shouldShowRateLaterButton]; + + if ([delegate respondsToSelector:@selector(appiraterDidAcceptPreliminaryAlert:)]) { + [delegate appiraterDidAcceptPreliminaryAlert:self]; + } + + break; + } + } + break; + case kRateAlertViewTag: + { + switch (buttonIndex) { + case RateAlertButtonIndexDontRate: + { + [self didDeclineToRate]; + break; + } + case RateAlertButtonIndexRateNow: + { + [Appirater rateApp]; + if(delegate&& [delegate respondsToSelector:@selector(appiraterDidOptToRate:)]){ + [delegate appiraterDidOptToRate:self]; + } + break; + } + case RateAlertButtonIndexRateLater: + [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate]; + [userDefaults synchronize]; + if(delegate && [delegate respondsToSelector:@selector(appiraterDidOptToRemindLater:)]){ + [delegate appiraterDidOptToRemindLater:self]; + } + break; + default: + break; + } + } + default: + break; + } +} + +- (void)didDeclineToRate { + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + + [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate]; + [userDefaults synchronize]; + if(_delegate && [_delegate respondsToSelector:@selector(appiraterDidDeclineToRate:)]){ + [_delegate appiraterDidDeclineToRate:self]; + } } //Delegate call from the StoreKit view. @@ -607,7 +691,6 @@ - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewContr //Close the in-app rating (StoreKit) view and restore the previous status bar style. + (void)closeModal { if (_modalOpen) { - [[UIApplication sharedApplication]setStatusBarStyle:_statusBarStyle animated:_usesAnimation]; BOOL usedAnimation = _usesAnimation; [self setModalOpen:NO]; diff --git a/AppiraterDelegate.h b/AppiraterDelegate.h index d7722d39..b5a7d7e7 100644 --- a/AppiraterDelegate.h +++ b/AppiraterDelegate.h @@ -13,6 +13,10 @@ @protocol AppiraterDelegate @optional +-(void)appiraterDidDisplayPreliminaryAlert:(Appirater *)appirater; +-(void)appiraterDidDeclinePreliminaryAlert:(Appirater *)appirater; +-(void)appiraterDidAcceptPreliminaryAlert:(Appirater *)appirater; + -(void)appiraterDidDisplayAlert:(Appirater *)appirater; -(void)appiraterDidDeclineToRate:(Appirater *)appirater; -(void)appiraterDidOptToRate:(Appirater *)appirater;