Permalink
Browse files

Merge pull request #104 from opentable/modal-fix

Fixed an issue with modal controller on iOS6+
  • Loading branch information...
2 parents 2cc6093 + 3c7b7bb commit 17f260fdbe42c3b40f964102636db9f62ad62021 @arashpayan committed Mar 12, 2013
Showing with 21 additions and 2 deletions.
  1. +21 −2 Appirater.m
View
@@ -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];
@@ -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];
}

0 comments on commit 17f260f

Please sign in to comment.