LoginSignup
3
1

More than 5 years have passed since last update.

Swift4でインカメラの使用

Posted at

Swift4でインカメラのを取得して使用。
備忘録なので当該箇所のみ。

var captureDevice: AVCaptureDevice?
    let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera, .builtInTelephotoCamera],
                                                            mediaType: AVMediaType.video,
                                                            position: .front)
    for device in discoverySession.devices {
        let devicePosition: AVCaptureDevice.Position = .front
        if (device as AnyObject).position == devicePosition {
            captureDevice = device
        }
    }
    if captureDevice == nil {
        print("Error: no camera devices available")
        return false
    }

    guard let videoInput = try? AVCaptureDeviceInput(device: captureDevice!) else {
      print("Error: could not create AVCaptureDeviceInput")
      return false
    }
  • .builtInTelephotoCamera は要らない気がするが念のため。
  • あとは videoInputAVCaptureSession にセットしてよしなにする。
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1