diff --git a/Appirater.m b/Appirater.m index 5c1ad5c1..6b39b124 100644 --- a/Appirater.m +++ b/Appirater.m @@ -37,6 +37,7 @@ #import "Appirater.h" #import #include +#import #if ! __has_feature(objc_arc) #warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). @@ -64,6 +65,8 @@ static UIStatusBarStyle _statusBarStyle; static BOOL _modalOpen = false; +static char SKStoreProductViewControllerPresentingController; + @interface Appirater () - (BOOL)connectedToNetwork; + (Appirater*)sharedInstance; @@ -449,7 +452,9 @@ + (void)rateApp { if ([self.sharedInstance.delegate respondsToSelector:@selector(appiraterWillPresentModalView:animated:)]) { [self.sharedInstance.delegate appiraterWillPresentModalView:self.sharedInstance animated:_usesAnimation]; } - [[self getRootViewController] presentViewController:storeViewController animated:_usesAnimation completion:^{ + id rootViewController = [self getRootViewController]; + objc_setAssociatedObject(self, &SKStoreProductViewControllerPresentingController, rootViewController, OBJC_ASSOCIATION_ASSIGN); + [rootViewController presentViewController:storeViewController animated:_usesAnimation completion:^{ [self setModalOpen:YES]; //Temporarily use a black status bar to match the StoreKit view. [self setStatusBarStyle:[UIApplication sharedApplication].statusBarStyle]; @@ -516,9 +521,8 @@ + (void)closeModal { BOOL usedAnimation = _usesAnimation; [self setModalOpen:NO]; - // get the top most controller (= the StoreKit Controller) and dismiss it - UIViewController *presentingController = [UIApplication sharedApplication].keyWindow.rootViewController; - presentingController = [self topMostViewController: presentingController]; + // Retrieve a reference to the UIViewController used to present the StoreKit view controller + UIViewController *presentingController = objc_getAssociatedObject(self, &SKStoreProductViewControllerPresentingController); [presentingController dismissViewControllerAnimated:_usesAnimation completion:^{ if ([self.sharedInstance.delegate respondsToSelector:@selector(appiraterDidDismissModalView:animated:)]) { [self.sharedInstance.delegate appiraterDidDismissModalView:(Appirater *)self animated:usedAnimation];