2016-10-30 7 views
1

Ich versuche eine benutzerdefinierte Kamera in Swift 3 für iOS 10.1 einzurichten.AVCaptureSession Swift 3 schlechtes Exec-Problem?

Ich erhalte die Fehlermeldung unter

"[MC] Systemgruppencontainer für systemgroup.com.apple.configurationprofiles Weg ist /private/var/containers/Shared/SystemGroup/systemgroup.com .apple.configurationprofiles aus öffentlichen effektiven Benutzereinstellungen lesen "

ich habe versucht, Hinzufügen von‚Privatleben -. Kamera Verwendung Beschreibung‘in info.plist, und das Mikrofon ein, aber immer noch die Frage.

Manchmal, wenn ich mein iPhone vom Code abkopple, erscheint die Nachricht, um die Kamera zu autorisieren, fast so, als ob es "stecken geblieben" und "gestoppt" wäre.

Kann jemand mit AVCaptureStillImageOutput umgehen? Es ist seit iOS 10 veraltet und ich möchte meine App für die Zukunft etwas kugelsicher machen.

import UIKit 
import AVFoundation 

class ViewController: UIViewController { 

var captureSession : AVCaptureSession? 
var stillImageOutput: AVCaptureStillImageOutput? 
var previewLayer : AVCaptureVideoPreviewLayer? 

@IBOutlet weak var cameraView: UIView! 

override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated) 
    captureSession?.sessionPreset = AVCaptureSessionPresetPhoto 

    let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.unspecified) 
    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?.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG] 
       } 
       if (captureSession?.canAddOutput(stillImageOutput))! { 
        captureSession?.addOutput(stillImageOutput) 
        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) 
        previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill 
        previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait 
        cameraView.layer.addSublayer(previewLayer!) 
        captureSession?.startRunning() 
       } 
      } catch{ 
       print("Error Occured when trying get camera") 
      } 
     } 
    } 
} 


override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


} 

Antwort

2

Gelöst ist das Problem!

Korrekter Code unten:

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") 
      } 
     } 
    } 
} 
+0

, dass die Kamera beginnt, aber wie stellen Sie es auf dem Bildschirm? Sorry, ich bin ein Neuling mit der Kamera auf IOS 10. – MLBDG

+0

Ich meine, sobald Sie eine UIView im Storyboard mit @IBOullet var cameraView verknüpfen: UIView! die Kamera wird nicht angezeigt (Ja, die Kameraberechtigungen sind in info.plist eingestellt) – MLBDG