Task <List <MediaFile> > GetMediasAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null, MultiPickerOptions pickerOptions = null, CancellationToken token = default(CancellationToken))
        {
            var viewController = GetHostViewController();

            if (options == null)
            {
                options = new StoreCameraMediaOptions();
            }

            var ndelegate = new MediaPickerDelegate(viewController, sourceType, options, token);
            var od        = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null);

            if (od != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            var picker = ELCImagePickerViewController.Create(options, pickerOptions);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary)
            {
                ndelegate.Popover          = popover = new UIPopoverController(picker);
                ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker);
                ndelegate.DisplayPopover();
            }
            else
            {
                if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    picker.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
                }
                viewController.PresentViewController(picker, true, null);
            }

            // TODO: Make this use the existing Delegate?
            return(picker.Completion.ContinueWith(t =>
            {
                Dismiss(popover, picker);
                picker.BeginInvokeOnMainThread(() =>
                {
                    picker.DismissViewController(true, null);
                });

                if (t.IsCanceled || t.Exception != null)
                {
                    return Task.FromResult(new List <MediaFile>());
                }

                var files = t.Result;
                Parallel.ForEach(files, mediaFile =>
                {
                    ResizeAndCompressImage(options, mediaFile, Path.GetExtension(mediaFile.Path).Replace(".", string.Empty));
                });

                return t;
            }).Unwrap());
        }
        /// <summary>
        /// Create a new instance of the Picker
        /// </summary>
        /// <param name="options">StoreCameraMediaOptions</param>
        /// <param name="maxImages">Max images.</param>
        /// <param name="selectAlbumTitle">Select album title.</param>
        /// <param name="pickPhotosTitle">Pick photos title.</param>
        /// <param name="backBattonTitle">Back batton title.</param>
        /// <param name="pickPhotoTitle">Pick photo title.</param>
        /// <param name="doneButtonTitle">Done button title.</param>
        /// <param name="loadingtitle">LoadingTitle.</param>
        public static ELCImagePickerViewController Create(StoreCameraMediaOptions options = null, int maxImages = 4, string selectAlbumTitle = null, string pickPhotosTitle = null, string backBattonTitle = null, string pickPhotoTitle = null, string doneButtonTitle = null, string loadingtitle = null, string pathToOverlay = null)
        {
            var albumPicker = new ELCAlbumPickerController()
            {
                SelectAlbumTitle = selectAlbumTitle,
                BackButtonTitle  = backBattonTitle,
                DoneButtonTitle  = doneButtonTitle,
                LoadingTitle     = loadingtitle,
                PickAssetTitle   = AssetTitle(maxImages, pickPhotoTitle, pickPhotosTitle),
            };

            var picker = new ELCImagePickerViewController(albumPicker, options);

            albumPicker.Parent        = picker;
            picker.MaximumImagesCount = maxImages;
            return(picker);
        }