2017-07-17 45 views
2
import UIKit 
import AVKit 

class ViewController: UIViewController { 
    override func viewDidLoad() { 
     super.viewDidLoad() 

//start camera 

     let captureSession = AVCaptureSession() 

     guard let captureDevice = 
      AVCaptureDevice.default(for: .video) else { return } 
     guard let input = try? AVCaptureDeviceInput(device: 
       captureDevice) else { return } 
     captureSession.addInput(input) 

     captureSession.startRunning() 
    } 
} 

我得到在此行中的誤差在(爲:。視頻):錯誤:輸入'String!'沒有成員 '視頻'

AVCaptureDevice.default(for: .video) else { return } 
+1

這很混亂。在iOS或MacOS中,AVKit中不存在「AVCaptureDevice」。 Foundation中存在一個版本,但它沒有'default'方法,*即使您的方法有文檔*。 – JeremyP

回答

0

方法

class func `default`(_ deviceType: AVCaptureDevice.DeviceType, 
      for mediaType: AVMediaType?, 
     position: AVCaptureDevice.Position) -> AVCaptureDevice? 

接受設備類型,這可以是:

AVCaptureDeviceTypeBuiltInMicrophone 
AVCaptureDeviceTypeBuiltInWideAngleCamera 
AVCaptureDeviceTypeBuiltInTelephotoCamera 
AVCaptureDeviceTypeBuiltInDualCamera 
AVCaptureDeviceTypeBuiltInDuoCamera 
+0

那麼我現在需要改變什麼呢?即時通訊對不起,即時通訊新:D – David

0

我想我已經想通了出。我一直在尋找的文件是對的Xcode 9.你需要的是率先導入AVFoundation,然後使用此功能:

class func defaultDevice(withDeviceType deviceType: AVCaptureDeviceType!, 
             mediaType: String!, 
              position: AVCaptureDevicePosition) -> AVCaptureDevice! 

https://developer.apple.com/documentation/avfoundation/avcapturedevice/2361508-default?changes=latest_minor

例如:

let c = AVCaptureDevice.defaultDevice(withDeviceType: AVCaptureDeviceType.builtInTelephotCamer, 
              mediaType: AVMediaTypeVideo, 
              position: AVCaptureDevicePosition.front) 
0

我只是試圖將我的項目轉換爲Swift4。這對我有用。

device = AVCaptureDevice.default(for: AVMediaType.video) 
2

用AVMediaTypeVideo替換AVMediaType.video爲我工作。

+0

工作。 Xcode還建議你將'for:'替換爲'forMediaType:'。以便它完全變成'forMediaType:AVMediaTypeVideo'。這可能是由於swift /這些apis的更新所致 – lelelo

相關問題