这是我的代码:
if AVCaptureDevice.authorizationStatus(for: AVMediaType.video) == .authorized {
let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(
deviceTypes: [.builtInDualCamera],
mediaType: AVMediaType.video,
position: .back)
let captureDevice = deviceDiscoverySession.devices.first
}
结果为空数组(deviceDiscoverySession.devices)。 我正在实际设备(iPhone 6+ iOS 12.1.2)上运行。
答案 0 :(得分:1)
您可以尝试
// Find a camera with the specified AVCaptureDevicePosition, returning nil if one is not found
func cameraWithPosition(position: AVCaptureDevice.Position) -> AVCaptureDevice? {
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
for device in discoverySession.devices {
if device.position == position {
return device
}
}
return nil
}
if let newCamera = cameraWithPosition(position: .back) {
//
}