ios - AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo 在 ipad 上返回 nil
问题描述
- (void)setupScanningSession {
// Initalising hte Capture session before doing any video capture/scanning.
NSError *error;
self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPresetMedium;
// Set camera capture device to default and the media type to video.
AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
// Set video capture input: If there a problem initialising the camera, it will give am error.
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
if (!input) {
NSLog(@"Error connecting camera: %@", [error localizedDescription]);
return;
}
// Adding input souce for capture session. i.e., Camera
[self.captureSession addInput:input];
当我尝试在真实设备上运行应用程序时,captureDevice 始终为零。iPad 是带有 iOS 12 的 A1474。
同一段代码在我的 iPhone 8 上完美运行。
解决方案
在把头发拉过这个之后,我终于找到了。我正在使用由我的公司管理的 iPad,并且相机被管理配置文件禁用。删除此配置文件后,iOS 内置相机应用程序也再次出现。
defaultDeviceWithMediaType 的调用不再为零。
也许这对发现此问题的其他人有所帮助。
推荐阅读
- javascript - 从 Firebase Firestore 异步返回数据
- laravel-6 - Laravel 6.5.2 在刷新时进入登录页面
- c++ - 无法从字符串流接收信息
- java - 方法@Produces在注入时返回null
- jestjs - 一个简单的 js 箭头函数的单元测试,它接收一个名称并返回一个总数
- python - django.core.exceptions.FieldError:为 CustomUser 指定的未知字段
- pointers - 在 Go 中,结构指针不是引用类型吗?
- python - 不明白为什么物体从墙上反弹/ Pygame
- google-bigquery - Google Analytics 和 BigQuery 之间的会话不匹配,同时将 hits 和 hits.product 取消嵌套
- javascript - 在最小化内存使用的同时调用对象数据的原型函数