我正在尝试启动默认的iOS相机应用程序进行视频录制,但它不起作用。
每当我启动应用程序时,它都会崩溃,并且不会显示任何错误日志或任何其他错误消息。
如果我将imagePicker.CameraCaptureMode
设置为UIImagePickerControllerCameraCaptureMode.Photo
,则以下代码可以正常运行。
var imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video;
var imagePickerDelegate = new ImagePickerDelegate(this);
imagePicker.Delegate = imagePickerDelegate;
NavigationController.PresentModalViewController(imagePicker, true);
提前致谢
答案 0 :(得分:4)
我这样做是为了工作:
var imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.MediaTypes = new string[]{ UTType.Movie }; // ADD this
var imagePickerDelegate = new ImagePickerDelegate(this);
imagePicker.Delegate = imagePickerDelegate;
NavigationController.PresentModalViewController(imagePicker, true);
您也可以这样设置委托调用:
imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
imagePicker.Canceled += Handle_Canceled;
然后创建这些方法:
protected void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
{
//code to handle picking media
}
void Handle_Canceled(object sender, EventArgs e)
{
imagePicker.DismissViewController(true, null);
}
<强>更新强>
在iOS 10中,您需要添加权限并在info.plist
见这里: