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

Fix bug in modal dismissal of SKStoreProductViewController #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions Appirater.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#import "Appirater.h"
#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>
#import <objc/runtime.h>

#if ! __has_feature(objc_arc)
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
Expand Down Expand Up @@ -64,6 +65,8 @@
static UIStatusBarStyle _statusBarStyle;
static BOOL _modalOpen = false;

static char SKStoreProductViewControllerPresentingController;

@interface Appirater ()
- (BOOL)connectedToNetwork;
+ (Appirater*)sharedInstance;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down