UIImagePickerController crashes application view

I am trying to represent a UIImagePickerController using a Button action. My project crashes with an error:

Got SIGABRT while executing native code. This usually indicates a fatal error in the mono executable version or one of the built-in libraries used by your application.

I only have a ViewController built into the NavigationController in the storyboard. The following are snippets of code:

UIImagePickerController imagePicker; public override void ViewDidLoad() { base.ViewDidLoad(); this.setupImagePicker(); CapturePhotoButton.TouchUpInside += delegate { this.AddMedia(); }; } public void setupImagePicker() { imagePicker = new UIImagePickerController(); imagePicker.SourceType = UIImagePickerControllerSourceType.Camera; imagePicker.ModalPresentationStyle = UIModalPresentationStyle.Popover; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes( UIImagePickerControllerSourceType.Camera); imagePicker.FinishedPickingMedia += HandleFinishedPickingMedia; imagePicker.Canceled += (sender, e) => { imagePicker.DismissModalViewController(true); }; } public void HandleFinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) { bool isImage = false; switch (e.Info[UIImagePickerController.MediaType].ToString()) { case "public.image": isImage = true; break; case "public.video": break; } if (isImage) { UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if (originalImage != null) { PreviewImageView.Image = originalImage; imagePicker.DismissViewController(true, null); } } } public void AddMedia() { //Crashes on this line this.NavigationController.PresentViewController(imagePicker, true, null); } 
+5
source share
2 answers

Added privacy - using the camera Description for your info.plist and solving this problem

+3
source

Add the following to your info.plist to use the camera:

 <key>NSCameraUsageDescription</key> <string>This app needs access to the camera to take photos.</string> 

for the library:

 <key>NSPhotoLibraryUsageDescription</key> <string>This app needs access to photos.</string> 
+2
source

All Articles