diff --git a/Example/QRCodeReader.swift/ViewController.swift b/Example/QRCodeReader.swift/ViewController.swift index 97ad2ea..60ac870 100644 --- a/Example/QRCodeReader.swift/ViewController.swift +++ b/Example/QRCodeReader.swift/ViewController.swift @@ -31,14 +31,22 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate { lazy var reader = QRCodeReaderViewController(metadataObjectTypes: [AVMetadataObjectTypeQRCode]) @IBAction func scanAction(sender: AnyObject) { + if QRCodeReader.isAvailable() && QRCodeReader.supportsMetadataObjectTypes() { reader.modalPresentationStyle = .FormSheet reader.delegate = self reader.completionBlock = { (result: String?) in - println(result) + println(result) } presentViewController(reader, animated: true, completion: nil) + } + else { + let alert = UIAlertController(title: "Error", message: "Reader not supported by the current device", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil)) + + presentViewController(alert, animated: true, completion: nil) + } } // MARK: - QRCodeReader Delegate Methods diff --git a/QRCodeReader.swift.podspec b/QRCodeReader.swift.podspec index 479453e..dc1b651 100644 --- a/QRCodeReader.swift.podspec +++ b/QRCodeReader.swift.podspec @@ -1,8 +1,8 @@ Pod::Spec.new do |s| s.name = 'QRCodeReader.swift' - s.version = '3.1.0' + s.version = '3.1.1' s.license = 'MIT' - s.summary = 'Simple QRCode reader in Swift' + s.summary = 'Simple QRCode and 1D bar code reader in Swift' s.homepage = 'https://github.com/yannickl/QRCodeReader.swift.git' s.social_media_url = 'https://twitter.com/yannickloriot' s.authors = { 'Yannick Loriot' => 'contact@yannickloriot.com' } diff --git a/QRCodeReader/QRCodeReader.swift b/QRCodeReader/QRCodeReader.swift index 8bb251b..a56ee3d 100644 --- a/QRCodeReader/QRCodeReader.swift +++ b/QRCodeReader/QRCodeReader.swift @@ -164,15 +164,18 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat return true } - /// Checks and return whether the given metadata object types are available - class func areMetadataObjectTypesAvailable(metadataObjectTypes: [String]) -> Bool { - if !isAvailable() { - return false - } - + /// 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() - for metadataObjectType in metadataObjectTypes { + var metadataObjectTypes = metadataTypes + + if metadataObjectTypes == nil || metadataObjectTypes?.count == 0 { + // Check the QRCode metadata object type by default + metadataObjectTypes = [AVMetadataObjectTypeQRCode] + } + + for metadataObjectType in metadataObjectTypes! { if !contains(output.availableMetadataObjectTypes, { $0 as String == metadataObjectType }) { return false } diff --git a/README.md b/README.md index 54102e8..fa2363d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ $ touch Podfile $ edit Podfile source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' -pod 'QRCodeReader.swift', '~> 3.1.0' +pod 'QRCodeReader.swift', '~> 3.1.1' ``` Install into your project: @@ -41,7 +41,7 @@ Open your project in Xcode from the .xcworkspace file (not the usual project fil $ open MyProject.xcworkspace ``` -Note that you have to use CocoaPods version 0.36, the pre-released version which supports swift. If you don't already have it, you can grab it with a single command. +*Note that you have to use CocoaPods version 0.36, the pre-released version which supports swift. If you don't already have it, you can grab it with a single command.* ``` bash [sudo] gem install cocoapods --pre @@ -84,6 +84,8 @@ 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.* + ## Contact Yannick Loriot