Working on a QR code reader. I am new to programming so this might be an easy fix. The error is "Type 'AVCaptureDevice' has no member 'defaultDevice'" Thanks for the help in advance!
//Creating session
let session = AVCaptureSession()
//Define capture device
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
do
{
let input = try AVCaptureDeviceInput(device: captureDevice)
session.addInput(input)
}
An AVCaptureDevice object represents a physical capture device and the properties associated with that device. You use a capture device to configure the properties of the underlying hardware. A capture device also provides input data (such as audio or video) to an AVCaptureSession object.
The default device for the mediaType, which should be a value from AVMediaType. An array of available AVCaptureDevice s that can capture mediaType. The device whose UniqueID matches deviceUniqueID. Indicates a change occurred to the indexes for a to-many relationship.
Whether the AVCaptureDevice supports the preset. Returns a string representation of the value of the current instance. Obsolete. With LockForConfiguration (NSError), commits the requested configuration changes.
Whether the app is permitted to capture the avMediaTypeToken. Gets the device-independent chromaticity values for the device-specific white balance RGB gains.. Returns the default device for the provided device and media types and front or back facing position. Returns the default device for the provided media type.
You are using the old Swift 2 API. The line:
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
should be:
let captureDevice = AVCaptureDevice.default(for: .video)
This is swift 3.0
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
In swift 4.1
AVCaptureDevice.default(for: AVMediaType.video)
{
let input = AVCaptureDeviceInput(device: captureDevice)
session.addInput(input)
}
I hope this will help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With