This commit is contained in:
asuchkov
2017-10-19 19:30:22 +03:00
parent 1e9ddbf3a9
commit b6b5acd823
32 changed files with 1766 additions and 764 deletions

View File

@@ -18,24 +18,107 @@ extension ZBarSymbolSet: Sequence {
}
}
@objc class ScannerViewController: UIViewController, ZBarReaderDelegate {
@objc class ScannerViewController: UIViewController, ZBarReaderDelegate, UITextFieldDelegate {
var platformChannel: FlutterMethodChannel?
let readerViewController = ZBarReaderViewController()
//Вьюшка для верхнего меню
let topView = UIView()
//Окно ввода кода
let textField = UITextField()
//Кнопка настроек
var settingButton: UIButton!
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)
readerViewController.showsZBarControls = false
settingButton = UIButton(type: .system)
settingButton.addTarget(self, action: #selector(ScannerViewController.buttonTouch), for: .touchUpInside)
self.addChildViewController(readerViewController)
self.view.addSubview(readerViewController.view)
readerViewController.view.addSubview(topView)
topView.addSubview(textField)
topView.addSubview(settingButton)
textField.delegate = self
textField.keyboardType = .numberPad
//Looks for single or multiple taps.
let tap = UITapGestureRecognizer(target: self, action: #selector(ScannerViewController.hideKeyboard))
readerViewController.view.addGestureRecognizer(tap)
}
func hideKeyboard() {
view.endEditing(false)
}
func buttonTouch(){
sendResult(textField.text!)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
sendResult(textField.text!)
return true
}
func sendResult(_ str: String) {
platformChannel?.invokeMethod("findUserAndPurchase", arguments: [str], result: { (result: Any?) in
if result is FlutterError {
self.showErrorAlert()
} else {
self.presentingViewController?.dismiss(animated: false, completion: { self.dismiss(animated: true) })
}
print("result: \(result.debugDescription )")
})
}
func showErrorAlert() {
let alertController = UIAlertController(title: "Error", message:
"Wrong code", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
override func viewWillAppear(_ animated: Bool) {
topView.backgroundColor = UIColor.white
settingButton.setTitle("+", for: .normal)
textField.placeholder = "Enter code"
textField.borderStyle = .roundedRect
//self.present(readerViewController, animated: true)
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewWillLayoutSubviews() {
readerViewController.view.frame = view.bounds
topView.frame = CGRect(x: 0, y: 0, width: readerViewController.view.frame.size.width, height: 40)
textField.frame = CGRect(x: 8, y: 5, width: readerViewController.view.frame.size.width - 50, height: 30)
settingButton.frame = CGRect(x: textField.frame.maxX + 8, y: 10, width: 20, height: 20)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
guard let symbols = info[ZBarReaderControllerResults] as? ZBarSymbolSet else { return }
@@ -43,30 +126,36 @@ extension ZBarSymbolSet: Sequence {
for symbol in symbols {
if let symbol = symbol as? ZBarSymbol, let data = symbol.data {
sendResult(data)
/*
if let platformChannel = self.platformChannel {
self.dismiss(animated: true, completion: {
self.presentingViewController?.dismiss(animated: true, completion: {
// self.dismiss(animated: true, completion: {
// self.presentingViewController?.dismiss(animated: true, completion: {
platformChannel.invokeMethod("findUserAndPurchase", arguments: [data], result: { (result: Any?) in
print("\(result ?? "")")
print("result: \(result ?? "")")
self.presentingViewController?.dismiss(animated: false, completion: { self.dismiss(animated: true) })
})
})
})
// })
// })
// let result = platformChannel.invokeMethod("getUserByCode", arguments: [data], handleResult(result: FlutterResult))
// print(result);
}
// let toast = UIAlertView()
// toast.message = data
// toast.show()
navigationController?.popViewController(animated: true)
/*
let toast = UIAlertController()
toast.message = data
toast.add
toast.show()
*/
//navigationController?.popViewController(animated: true)
*/
}
}
navigationController?.popViewController(animated: true)
//navigationController?.popViewController(animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}