From 271c59b5a47d76d6d50a3de24d776b0d0b8e0983 Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Thu, 20 Aug 2015 16:25:45 -0700 Subject: [PATCH] Fixed presentation of PFAlertView when rootViewController has presentedViewController. --- Parse/Internal/PFAlertView.m | 3 +++ Tests/Unit/AlertViewTests.m | 1 + 2 files changed, 4 insertions(+) diff --git a/Parse/Internal/PFAlertView.m b/Parse/Internal/PFAlertView.m index 0e542b0cd..3c7e7b4f3 100644 --- a/Parse/Internal/PFAlertView.m +++ b/Parse/Internal/PFAlertView.m @@ -52,6 +52,9 @@ + (void)showAlertWithTitle:(NSString *)title UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; UIViewController *viewController = keyWindow.rootViewController; + while (viewController.presentedViewController) { + viewController = viewController.presentedViewController; + } [viewController presentViewController:alertController animated:YES completion:nil]; } else { diff --git a/Tests/Unit/AlertViewTests.m b/Tests/Unit/AlertViewTests.m index d555967fb..67efc572b 100644 --- a/Tests/Unit/AlertViewTests.m +++ b/Tests/Unit/AlertViewTests.m @@ -44,6 +44,7 @@ - (void)testShowAlertWithAlertViewController { id mockedApplication = PFStrictClassMock([UIApplication class]); UIWindow *mockedWindow = PFStrictClassMock([UIWindow class]); UIViewController *mockedViewController = PFStrictClassMock([UIViewController class]); + OCMStub(mockedViewController.presentedViewController).andReturn(nil); // Using .andReturn() here will result in a retain cycle, which will cause our mocked shared application to // persist across tests.