[UPDATE] Documentation and example project to check whether the reader is available
This commit is contained in:
parent
e0c3824442
commit
42a93f814a
|
@ -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
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue