public Task <string> FromGallery()
        {
            UIWindow window = GetRootWindow();

            if (window == null)
            {
                throw new InvalidOperationException("No root controller.");
            }

            var viewController = window.RootViewController;

            while (viewController.PresentedViewController != null)
            {
                viewController = viewController.PresentedViewController;
            }

            var ndelegate = new GalleryDelegate(viewController);
            var od        = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null);

            if (od != null)
            {
                throw new InvalidOperationException("Delegate still running");
            }

            var picker = new GalleryController(ndelegate)
            {
                MediaTypes = new string[] { "public.image" },
                SourceType = UIImagePickerControllerSourceType.PhotoLibrary
            };

            viewController.PresentViewController(picker, true, null);

            return(ndelegate.Task.ContinueWith(
                       t =>
            {
                Interlocked.Exchange(ref pickerDelegate, null);
                return t;
            }).Unwrap());
        }
 internal GalleryController(GalleryDelegate mpDelegate)
 {
     base.Delegate = mpDelegate;
 }