From e9b7f6b63a3fc442d59a7c8fcd7954166a00ceed Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Wed, 23 Nov 2016 12:21:54 -0800 Subject: [PATCH] Revert VC changes, do modal popover fixes #130 Need to make sure it is over current context --- src/Media.Plugin.iOS/MediaImplementation.cs | 43 +++++++++------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/Media.Plugin.iOS/MediaImplementation.cs b/src/Media.Plugin.iOS/MediaImplementation.cs index caaabd56..be12aefa 100644 --- a/src/Media.Plugin.iOS/MediaImplementation.cs +++ b/src/Media.Plugin.iOS/MediaImplementation.cs @@ -267,36 +267,25 @@ private static MediaPickerController SetupController(MediaPickerDelegate mpDeleg return picker; } - /// - /// Gets the visible view controller. - /// - /// The visible view controller. - UIViewController GetVisibleViewController() + private Task GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null) { - var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; - - if (rootController.PresentedViewController == null) - return rootController; + UIWindow window = UIApplication.SharedApplication.KeyWindow; + if (window == null) + throw new InvalidOperationException("There's no current active window"); - if (rootController.PresentedViewController is UINavigationController) - { - return ((UINavigationController)rootController.PresentedViewController).VisibleViewController; - } + UIViewController viewController = window.RootViewController; - if (rootController.PresentedViewController is UITabBarController) + if (viewController == null) { - return ((UITabBarController)rootController.PresentedViewController).SelectedViewController; + window = UIApplication.SharedApplication.Windows.OrderByDescending(w => w.WindowLevel).FirstOrDefault(w => w.RootViewController != null); + if (window == null) + throw new InvalidOperationException("Could not find current view controller"); + else + viewController = window.RootViewController; } - return rootController.PresentedViewController; - } - - private Task GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null) - { - - - var viewController = GetVisibleViewController(); - + while (viewController.PresentedViewController != null) + viewController = viewController.PresentedViewController; MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options); var od = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null); @@ -312,7 +301,13 @@ private Task GetMediaAsync(UIImagePickerControllerSourceType sourceTy ndelegate.DisplayPopover(); } else + { + if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) + { + picker.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext; + } viewController.PresentViewController(picker, true, null); + } return ndelegate.Task.ContinueWith(t => {