ScanHelper.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // ScanHelper.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2018/9/30.
  6. // Copyright © 2018 zoneland. All rights reserved.
  7. //
  8. import AVFoundation
  9. class ScanHelper {
  10. static func openScan(vc: UIViewController, callbackResult: ((String)->Void)? = nil) {
  11. //新版本 仿新版微信 全屏扫码
  12. let scanVC = ScanQRViewController()
  13. scanVC.resultBlock = { result in
  14. let o2Check = QRCodeResultViewController.checkResultIsO2(result: result)
  15. if let callback = callbackResult, !(o2Check.0 || !o2Check.1.isEmpty) {
  16. callback(result)
  17. } else {
  18. QRCodeResultViewController.openQRResult(result: result, vc: vc)
  19. }
  20. }
  21. scanVC.modalPresentationStyle = .fullScreen
  22. vc.present(scanVC, animated: true, completion: nil)
  23. //老版本
  24. // LBXPermissions.authorizeCameraWith { (result) in
  25. // if result {
  26. // if let scanVC = self.initScanViewController(callbackResult: callbackResult) {
  27. // vc.navigationController?.pushViewController(scanVC, animated: false)
  28. // }else {
  29. // vc.gotoApplicationSettings(alertMessage: "是否跳转到手机设置页面开启相机权限?")
  30. // }
  31. // }else {
  32. // vc.showError(title: "没有摄像头权限,请先开启!")
  33. // }
  34. // }
  35. }
  36. /// 生成扫码的ViewController 如果没有权限就返回nil
  37. static private func initScanViewController(callbackResult: ((String)->Void)? = nil) -> NewScanViewController? {
  38. let scanVC = NewScanViewController()
  39. var scanStyle = LBXScanViewStyle()
  40. scanStyle.centerUpOffset = 44
  41. scanStyle.photoframeAngleStyle = LBXScanViewPhotoframeAngleStyle.Inner
  42. scanStyle.photoframeLineW = 2
  43. scanStyle.photoframeAngleW = 18
  44. scanStyle.photoframeAngleH = 18
  45. scanStyle.isNeedShowRetangle = false
  46. scanStyle.anmiationStyle = LBXScanViewAnimationStyle.LineMove
  47. //scanStyle.colorAngle = UIColor(red: 0.0/255, green: 200.0/255.0, blue: 20.0/255.0, alpha: 1.0)
  48. scanStyle.colorAngle = O2ThemeManager.color(for: "Base.base_color") ?? UIColor.init(hex: "#fb47474")
  49. scanStyle.animationImage = UIImage(named: "qrcode_scan_part_net.png")
  50. scanVC.scanStyle = scanStyle
  51. scanVC.callbackResult = callbackResult
  52. return scanVC
  53. }
  54. }