75 lines
2.4 KiB
Swift
75 lines
2.4 KiB
Swift
//
|
|
// ScannerViewController.swift
|
|
// Runner
|
|
//
|
|
// Created by Ivan Murashov on 13/07/2017.
|
|
// Copyright © 2017 The Chromium Authors. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Flutter
|
|
|
|
extension ZBarSymbolSet: Sequence {
|
|
//public typealias Element = ZBarSymbol
|
|
//public typealias Iterator = NSFastEnumerationIterator
|
|
|
|
public func makeIterator() -> NSFastEnumerationIterator {
|
|
return NSFastEnumerationIterator(self)
|
|
}
|
|
}
|
|
|
|
@objc class ScannerViewController: UIViewController, ZBarReaderDelegate {
|
|
var platformChannel: FlutterMethodChannel?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
}
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
let readerViewController = ZBarReaderViewController()
|
|
readerViewController.readerDelegate = self
|
|
readerViewController.readerView.zoom = 1.0
|
|
readerViewController.showsZBarControls = true
|
|
self.present(readerViewController, animated: true)
|
|
}
|
|
|
|
|
|
|
|
|
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
|
|
guard let symbols = info[ZBarReaderControllerResults] as? ZBarSymbolSet else { return }
|
|
|
|
for symbol in symbols {
|
|
|
|
if let symbol = symbol as? ZBarSymbol, let data = symbol.data {
|
|
|
|
if let platformChannel = self.platformChannel {
|
|
self.dismiss(animated: true, completion: {
|
|
self.presentingViewController?.dismiss(animated: true, completion: {
|
|
platformChannel.invokeMethod("findUserAndPurchase", arguments: [data], result: { (result: Any?) in
|
|
print("\(result ?? "")")
|
|
})
|
|
})
|
|
})
|
|
// let result = platformChannel.invokeMethod("getUserByCode", arguments: [data], handleResult(result: FlutterResult))
|
|
// print(result);
|
|
}
|
|
|
|
// let toast = UIAlertView()
|
|
// toast.message = data
|
|
// toast.show()
|
|
|
|
navigationController?.popViewController(animated: true)
|
|
}
|
|
}
|
|
navigationController?.popViewController(animated: true)
|
|
|
|
}
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
}
|
|
|
|
}
|