gpt4 book ai didi

ios - 无法使用 iOS 默认相机应用程序捕获视频。 Xamarin.iOS

转载 作者:可可西里 更新时间:2023-11-01 05:40:22 25 4
gpt4 key购买 nike

我正在尝试启动用于视频录制的默认 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);

提前致谢

最佳答案

我通过这样做让它工作:

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

你也可以像这样设置你的委托(delegate)调用:

    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

中提供有关请求权限原因的说明

看这里:

iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash

关于ios - 无法使用 iOS 默认相机应用程序捕获视频。 Xamarin.iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36956593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com