| | |
| | | |
| | | import UIKit |
| | | import AVKit |
| | | import JQTools |
| | | import SceneKit |
| | | |
| | | class CommonScanQRCodeVC: BaseVC,AVCaptureMetadataOutputObjectsDelegate { |
| | | |
| | |
| | | public override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "扫描二维码" |
| | | if UIImagePickerController.isSourceTypeAvailable(.camera){ |
| | | |
| | | if borderView == nil { |
| | | borderView = UIImageView(image: UIImage(named: "ty_qrcode_bg")) |
| | | } |
| | | |
| | | if scanLineView == nil { |
| | | scanLineView = UIImageView(image: UIImage(named: "ty_qrcode_line")) |
| | | } |
| | | |
| | | if closeBtn == nil && modalPresentationStyle == .fullScreen && self.presentationController != nil { |
| | | closeBtn = UIButton(type: .custom) |
| | | closeBtn!.addTarget(self, action: #selector(closeView), for: .touchUpInside) |
| | | let image = Bundle.JQ_Bundle(icon: "close_btn") |
| | | closeBtn!.setImage(image, for: .normal) |
| | | view.addSubview(closeBtn!) |
| | | closeBtn!.snp.makeConstraints { (make) in |
| | | make.top.equalTo(30) |
| | | make.left.equalTo(20) |
| | | make.width.height.equalTo(30) |
| | | if borderView == nil { |
| | | borderView = UIImageView(image: UIImage(named: "ty_qrcode_bg")) |
| | | } |
| | | } |
| | | |
| | | let authStatus = AVCaptureDevice.authorizationStatus(for: AVMediaType.video) |
| | | if authStatus == AVAuthorizationStatus.notDetermined { |
| | | AVCaptureDevice.requestAccess(for: AVMediaType.video) { (granted) in |
| | | if granted{ |
| | | self.limitSuccess() |
| | | }else{ |
| | | self.limitFaild() |
| | | if scanLineView == nil { |
| | | scanLineView = UIImageView(image: UIImage(named: "ty_qrcode_line")) |
| | | } |
| | | |
| | | if closeBtn == nil && modalPresentationStyle == .fullScreen && self.presentationController != nil { |
| | | closeBtn = UIButton(type: .custom) |
| | | closeBtn!.addTarget(self, action: #selector(closeView), for: .touchUpInside) |
| | | let image = Bundle.JQ_Bundle(icon: "close_btn") |
| | | closeBtn!.setImage(image, for: .normal) |
| | | view.addSubview(closeBtn!) |
| | | closeBtn!.snp.makeConstraints { (make) in |
| | | make.top.equalTo(30) |
| | | make.left.equalTo(20) |
| | | make.width.height.equalTo(30) |
| | | } |
| | | } |
| | | } else if authStatus == AVAuthorizationStatus.restricted || authStatus == AVAuthorizationStatus.denied { |
| | | limitFaild() |
| | | } else { |
| | | limitSuccess() |
| | | |
| | | let authStatus = AVCaptureDevice.authorizationStatus(for: AVMediaType.video) |
| | | if authStatus == AVAuthorizationStatus.notDetermined { |
| | | AVCaptureDevice.requestAccess(for: AVMediaType.video) { (granted) in |
| | | if granted{ |
| | | self.limitSuccess() |
| | | }else{ |
| | | self.limitFaild() |
| | | } |
| | | } |
| | | } else if authStatus == AVAuthorizationStatus.restricted || authStatus == AVAuthorizationStatus.denied { |
| | | limitFaild() |
| | | } else { |
| | | limitSuccess() |
| | | } |
| | | }else{ |
| | | alertError(msg: "当前环境相机不可用") |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) { |
| | | self.navigationController?.popViewController() |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // if(!checkCameraAuth()){ |
| | |
| | | alertController.addAction(cancelAction) |
| | | alertController.addAction(okAction) |
| | | self.present(alertController, animated: true, completion: nil) |
| | | } |
| | | |
| | | public override func viewWillAppear(_ animated: Bool) { |
| | | firstResult = true |
| | | if let session = self.session { |
| | | let queue = DispatchQueue(label: "startRun") |
| | | queue.async { |
| | | session.startRunning() |
| | | } |
| | | } |
| | | scanTimer?.fireDate = NSDate.distantPast |
| | | } |
| | | |
| | | func checkCameraAuth() -> Bool { |