Skip to content

Commit

Permalink
Merge pull request #104 from opentable/modal-fix
Browse files Browse the repository at this point in the history
Fixed an issue with modal controller on iOS6+
  • Loading branch information
arashpayan committed Mar 12, 2013
2 parents 2cc6093 + 3c7b7bb commit 17f260f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Appirater.m
Expand Up @@ -391,13 +391,28 @@ + (id)getRootViewController {
{
UIResponder *responder = [subView nextResponder];
if([responder isKindOfClass:[UIViewController class]]) {
return responder;
return [self topMostViewController: (UIViewController *) responder];
}
}

return nil;
}

+ (UIViewController *) topMostViewController: (UIViewController *) controller {
BOOL isPresenting = NO;
do {
// this path is called only on iOS 6+, so -presentedViewController is fine here.
UIViewController *presented = [controller presentedViewController];
isPresenting = presented != nil;
if(presented != nil) {
controller = presented;
}

} while (isPresenting);

return controller;
}

+ (void)rateApp {

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
Expand Down Expand Up @@ -480,7 +495,11 @@ + (void)closeModal {
[[UIApplication sharedApplication]setStatusBarStyle:_statusBarStyle animated:_usesAnimation];
BOOL usedAnimation = _usesAnimation;
[self setModalOpen:NO];
[[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:_usesAnimation completion:^{

// get the top most controller (= the StoreKit Controller) and dismiss it
UIViewController *presentingController = [UIApplication sharedApplication].keyWindow.rootViewController;
presentingController = [self topMostViewController: presentingController];
[presentingController dismissViewControllerAnimated:_usesAnimation completion:^{
if ([self.sharedInstance.delegate respondsToSelector:@selector(appiraterDidDismissModalView:animated:)]) {
[self.sharedInstance.delegate appiraterDidDismissModalView:(Appirater *)self animated:usedAnimation];
}
Expand Down

0 comments on commit 17f260f

Please sign in to comment.