[FIX] The delegate is never called

This commit is contained in:
Yannick Loriot 2015-03-05 11:18:56 +01:00
parent cb350c766e
commit 764aedd6ff
4 changed files with 22 additions and 19 deletions

View File

@ -36,7 +36,7 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
reader.delegate = self
reader.completionBlock = { (result: String?) in
println(result)
println("Completion with result: \(result)")
}
presentViewController(reader, animated: true, completion: nil)
@ -52,7 +52,12 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
// MARK: - QRCodeReader Delegate Methods
func reader(reader: QRCodeReaderViewController, didScanResult result: String) {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismissViewControllerAnimated(true, completion: { [unowned self] () -> Void in
let alert = UIAlertController(title: "QRCodeReader", message: result, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
})
}
func readerDidCancel(reader: QRCodeReaderViewController) {

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'QRCodeReader.swift'
s.version = '3.1.2'
s.version = '3.1.3'
s.license = 'MIT'
s.summary = 'Simple QRCode and 1D bar code reader in Swift'
s.homepage = 'https://github.com/yannickl/QRCodeReader.swift.git'

View File

@ -35,21 +35,7 @@ public final class QRCodeReaderViewController: UIViewController {
private var switchCameraButton: SwitchCameraButton?
weak var delegate: QRCodeReaderViewControllerDelegate?
var completionBlock: ((String?) -> ())? {
didSet {
if let _completionBlock = completionBlock {
codeReader?.completionBlock = { [unowned self] (resultAsString) in
_completionBlock(resultAsString)
if let _delegate = self.delegate {
if let _resultAsString = resultAsString {
_delegate.reader(self, didScanResult: _resultAsString)
}
}
}
}
}
}
var completionBlock: ((String?) -> ())?
deinit {
codeReader?.stopScanning()
@ -80,6 +66,18 @@ public final class QRCodeReaderViewController: UIViewController {
codeReader = reader
view.backgroundColor = UIColor.blackColor()
codeReader?.completionBlock = { [unowned self] (resultAsString) in
if let _completionBlock = self.completionBlock {
_completionBlock(resultAsString)
}
if let _delegate = self.delegate {
if let _resultAsString = resultAsString {
_delegate.reader(self, didScanResult: _resultAsString)
}
}
}
setupUIComponentsWithCancelButtonTitle(cancelButtonTitle)
setupAutoLayoutConstraints()

View File

@ -26,7 +26,7 @@ $ touch Podfile
$ edit Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'QRCodeReader.swift', '~> 3.1.2'
pod 'QRCodeReader.swift', '~> 3.1.3'
```
Install into your project: