objective-c - 找不到 iOS 10 的相机(AVFoundation 新 API)类

标签 objective-c avfoundation ios10

我遇到错误:没有已知的选择器方法

defaultDeviceWithDeviceType:mediaType:position:

虽然此方法的文档位于: AVCap

当我调用这个方法时,它显示错误,找不到该方法。我的代码是:

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithDeviceType: AVCaptureDeviceTypeBuiltInDuoCamera
                                            mediaType: AVMediaTypeVideo
                                             position: AVCaptureDevicePositionBack];

以下是所有版本详细信息: 苹果系统:10.11.5, xCode:8.0 测试版, iOS:10.0.1

最佳答案

The AVCaptureDevice methods devices and devicesWithMediaType: are deprecated in iOS 10, and do not provide access to the dual camera or telephoto camera.

When you use the AVCaptureDevice class for video or photo capture, you can choose to use the dual camera device to gain these features, or to specifically use only the wide-angle or telephoto camera for more manual control.

要在 iOS 10.0 及更高版本中访问捕获设备,您可以使用以下方法之一:

调用defaultDeviceWithDeviceType:mediaType:position:方法。 (通过AVCaptureDeviceTypeBuiltInDuoCamera设备类型来访问双摄像头。

对于没有双摄像头的设备,该调用返回 nil - 在这种情况下,您可以再次调用相同的方法,传递 AVCaptureDeviceTypeBuiltInWideAngleCamera 设备类型,以获得默认的后置摄像头。)

创建一个 AVCaptureDeviceDiscoverySession 对象,传递要用于捕获的设备属性,并枚举其设备列表以选择用于捕获 session 的设备。

在此处阅读文档:

https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html#//apple_ref/doc/uid/TP40017084-DontLinkElementID_11

关于objective-c - 找不到 iOS 10 的相机(AVFoundation 新 API)类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39635730/

相关文章:

objective-c - 如何按位与 CFBitVector

swift - 如何在 Swift 中重复播放音乐

ios - 如何在ios的耳机中播放音频?

iphone - 在 iPhone 中生成随机值

iphone - 为 Objective-C 数据对象分配内存的问题

ios - 不使用桥接 header 访问私有(private) UIKit 函数

ios - [AVPlayerLayer super View ] : unrecognized selector sent to instance in Swift

swift iOS11 - 识别 keyboardSize 高度不再起作用

ios - xcode 8 和 swift 3 - PHPhotoLibrary.requestAuthorization 崩溃

xcode - 今天扩展 : How to work with display mode?