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.