Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active December 29, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/a034c2b99f76dc906e975a51448fbef9 to your computer and use it in GitHub Desktop.
Save sturdysturge/a034c2b99f76dc906e975a51448fbef9 to your computer and use it in GitHub Desktop.
CameraView for camera feed
import SwiftUI
import AVFoundation
struct CameraView: UIViewRepresentable {
let preview = PreviewView()
func makeUIView(context: Context) -> PreviewView {
AVCaptureDevice.requestAccess(for: .video) { granted in
if granted {
DispatchQueue.main.async {
preview.videoPreviewLayer.session = AVCaptureSession(device: .builtInWideAngleCamera)
}
}
}
return preview
}
func updateUIView(_ uiView: PreviewView, context: Context) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment