I'm building an app with media picker support, I've used the example from the Xamarin.Forms.Labs project to build it and untill the upgrade to iOS 8 it worked perfectly. After the upgrade though I found out that whenever I open one of the screens of the media picker on iOS it dismisses itself immediatly.
Here is my code.
private Task<MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, MediaStorageOptions options = null)
{
UIWindow window = UIApplication.SharedApplication.KeyWindow;
if (window == null)
throw new InvalidOperationException("There's no current active window");
UIViewController viewController = window.RootViewController;
if (viewController == null)
{
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;
}
while (viewController.PresentedViewController != null)
viewController = viewController.PresentedViewController;
MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options);
var od = Interlocked.CompareExchange(ref this.pickerDelegate, ndelegate, null);
if (od != null)
throw new InvalidOperationException("Only one operation can be active at at time");
var picker = SetupController(ndelegate, sourceType, mediaType, options);
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary)
{
ndelegate.Popover = new UIPopoverController(picker);
ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker);
ndelegate.DisplayPopover();
}
else
viewController.PresentViewController(picker, true, null);
return ndelegate.Task.ContinueWith(t =>
{
if (this.popover != null)
{
this.popover.Dispose();
this.popover = null;
}
Interlocked.Exchange(ref this.pickerDelegate, null);
return t;
}).Unwrap();
}
And the MediaPickercontroller
public sealed class MediaPickerController : UIImagePickerController
{
internal MediaPickerController(MediaPickerDelegate mpDelegate)
{
base.Delegate = mpDelegate;
}
public override MonoTouch.Foundation.NSObject Delegate
{
get { return base.Delegate; }
set { throw new NotSupportedException(); }
}
public Task<MediaFile> GetResultAsync()
{
return ((MediaPickerDelegate)Delegate).Task;
}
}