我正在尝试在swift 3中为iOS 10.1设置自定义相机。
我一直收到
下面的错误消息“[MC]系统组容器 systemgroup.com.apple.configurationprofiles路径是 /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 从公共有效用户设置中读取。 “
我尝试将“隐私 - 相机使用说明”添加到info.plist和麦克风中,但仍有问题。
有时当我从代码中断开我的iPhone时,会发出授权相机的消息,就好像它被“卡住”和“停止”一样?
有没有人知道如何使用AVCaptureStillImageOutput?它在iOS 10以后已被弃用,我想让我的应用程序在未来有点防弹。
$_GET
答案 0 :(得分:2)
解决了这个问题!
以下正确代码:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// setting up the camera session
captureSession = AVCaptureSession()
captureSession?.sessionPreset = AVCaptureSessionPreset1920x1080
let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.front)
for device in (deviceDiscoverySession?.devices)! {
if device.position == AVCaptureDevicePosition.front{
do {
let input = try AVCaptureDeviceInput(device: device)
if (captureSession?.canAddInput(input))!{
captureSession?.addInput(input)
stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput?.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG]
if (captureSession?.canAddOutput(stillImageOutput))! {
captureSession?.addOutput(stillImageOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait
cameraView.layer.addSublayer(previewLayer!)
captureSession?.startRunning()
}
}
} catch{
print("Error Occured when trying get camera")
}
}
}
}