[FIX] The delegate is never called
This commit is contained in:
parent
cb350c766e
commit
764aedd6ff
|
@ -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) {
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue