partial void ShowPHImagePicker(NSObject sender) { var config = new PHPickerConfiguration { Filter = PHPickerFilter.ImagesFilter, SelectionLimit = 0 }; var picker = new PHPickerViewController(config) { ModalPresentationStyle = UIModalPresentationStyle.Popover, Delegate = new PickerDelegate(imagePreview) }; var popPC = picker.PopoverPresentationController; popPC.PermittedArrowDirections = UIPopoverArrowDirection.Any; popPC.SourceView = uiImagePickerButton; popPC.SourceRect = uiImagePickerButton.Bounds; ShowViewController(picker, this); }
static async Task <IEnumerable <IMediaFile> > PlatformPickAsync(int selectionLimit, params MediaFileType[] types) { var vc = GetCurrentUIViewController(); var isVideo = types.Contains(MediaFileType.Video); var isImage = types.Contains(MediaFileType.Image); var tcs = new TaskCompletionSource <IEnumerable <IMediaFile> >(); if (HasOSVersion(14)) { var config = new PHPickerConfiguration(); config.SelectionLimit = selectionLimit; if (!(isVideo && isImage)) { config.Filter = isVideo ? PHPickerFilter.VideosFilter : PHPickerFilter.ImagesFilter; } pickerRef = new PHPickerViewController(config) { Delegate = new PHPickerDelegate(tcs) }; } else { var sourceType = UIImagePickerControllerSourceType.PhotoLibrary; if (!UIImagePickerController.IsSourceTypeAvailable(sourceType)) { throw new FeatureNotSupportedException(); } var availableTypes = UIImagePickerController.AvailableMediaTypes(sourceType); isVideo = isVideo && availableTypes.Contains(UTType.Movie); isImage = isImage && availableTypes.Contains(UTType.Image); if (!(isVideo || isImage)) { throw new FeatureNotSupportedException(); } pickerRef = new UIImagePickerController { SourceType = sourceType, AllowsEditing = false, AllowsImageEditing = false, Delegate = new PhotoPickerDelegate(tcs), MediaTypes = isVideo && isImage ? new string[] { UTType.Movie, UTType.Image } : new string[] { isVideo?UTType.Movie : UTType.Image } }; } if (pickerRef.PresentationController != null) { pickerRef.PresentationController.Delegate = new PresentatControllerDelegate(tcs); } if (DeviceInfo.Idiom == DeviceIdiom.Tablet && pickerRef.PopoverPresentationController != null && vc.View != null) { pickerRef.PopoverPresentationController.SourceRect = vc.View.Bounds; } await vc.PresentViewControllerAsync(pickerRef, true); var result = await tcs.Task; pickerRef?.Dispose(); pickerRef = null; return(result); }