[FIX] Metatada object type support validation
This commit is contained in:
parent
42a93f814a
commit
cb350c766e
|
@ -31,7 +31,7 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
|
|||
lazy var reader = QRCodeReaderViewController(metadataObjectTypes: [AVMetadataObjectTypeQRCode])
|
||||
|
||||
@IBAction func scanAction(sender: AnyObject) {
|
||||
if QRCodeReader.isAvailable() && QRCodeReader.supportsMetadataObjectTypes() {
|
||||
if QRCodeReader.supportsMetadataObjectTypes() {
|
||||
reader.modalPresentationStyle = .FormSheet
|
||||
reader.delegate = self
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'QRCodeReader.swift'
|
||||
s.version = '3.1.1'
|
||||
s.version = '3.1.2'
|
||||
s.license = 'MIT'
|
||||
s.summary = 'Simple QRCode and 1D bar code reader in Swift'
|
||||
s.homepage = 'https://github.com/yannickl/QRCodeReader.swift.git'
|
||||
|
|
|
@ -55,8 +55,8 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
|||
|
||||
return nil
|
||||
}()
|
||||
private var metadataOutput: AVCaptureMetadataOutput = AVCaptureMetadataOutput()
|
||||
private var session: AVCaptureSession = AVCaptureSession()
|
||||
private var metadataOutput = AVCaptureMetadataOutput()
|
||||
private var session = AVCaptureSession()
|
||||
|
||||
/// CALayer that you use to display video as it is being captured by an input device.
|
||||
public lazy var previewLayer: AVCaptureVideoPreviewLayer = { return AVCaptureVideoPreviewLayer(session: self.session) }()
|
||||
|
@ -166,7 +166,18 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
|||
|
||||
/// Checks and return whether the given metadata object types are supported by the current device
|
||||
class func supportsMetadataObjectTypes(_ metadataTypes: [String]? = nil) -> Bool {
|
||||
let output = AVCaptureMetadataOutput()
|
||||
if !isAvailable() {
|
||||
return false
|
||||
}
|
||||
|
||||
// Setup components
|
||||
let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) as AVCaptureDevice
|
||||
let deviceInput = AVCaptureDeviceInput.deviceInputWithDevice(captureDevice, error: nil) as AVCaptureDeviceInput
|
||||
let output = AVCaptureMetadataOutput()
|
||||
let session = AVCaptureSession()
|
||||
|
||||
session.addInput(deviceInput)
|
||||
session.addOutput(output)
|
||||
|
||||
var metadataObjectTypes = metadataTypes
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ $ touch Podfile
|
|||
$ edit Podfile
|
||||
source 'https://github.com/CocoaPods/Specs.git'
|
||||
platform :ios, '8.0'
|
||||
pod 'QRCodeReader.swift', '~> 3.1.1'
|
||||
pod 'QRCodeReader.swift', '~> 3.1.2'
|
||||
```
|
||||
|
||||
Install into your project:
|
||||
|
@ -84,7 +84,7 @@ func readerDidCancel(reader: QRCodeReader) {
|
|||
}
|
||||
```
|
||||
|
||||
*Note that you should check whether the device supports the reader library by using the `QRCodeReader.isAvailable()` and the `QRCodeReader.supportsMetadataObjectTypes()` methods.*
|
||||
*Note that you should check whether the device supports the reader library by using the `QRCodeReader.isAvailable()` or the `QRCodeReader.supportsMetadataObjectTypes()` methods.*
|
||||
|
||||
## Contact
|
||||
|
||||
|
|
Loading…
Reference in New Issue