2016-09-19 173 views
5

我想通过按钮操作呈现UIImagePickerController。我的项目崩溃的错误:介绍UIImagePickerController崩溃应用程序

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

我只有一个ViewController嵌入在故事板的NavigationController中。相机用法说明您的info.plist和解决问题

+0

不是ViewController本身有一个PresentViewController方法吗?你可以尝试使用它来查看是否有任何区别? 'this.PresentViewController(imagePicker,true,null);' – Cheesebaron

+0

也尝试过,它仍然在演示文稿上崩溃 – DrPatience

+0

你是否放弃了? @Cheesebaron – DrPatience

回答

3

私密:

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

下面的代码片段对于库:

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

完全相同的问题,这个问题解决了。我很惊讶iTunes Connect对应用程序的分析没有抓住这一点。谢谢! – JHawkZZ

2

以下添加到您的info.plist对摄像机 -

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); 
}