From f6d11ec2e3ea229dce9417156319f25e345f58a5 Mon Sep 17 00:00:00 2001 From: dvlprliu Date: Tue, 4 Sep 2018 11:19:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=8A=E8=AF=B7=E6=B1=82=E7=9B=B8?= =?UTF-8?q?=E6=9C=BA=E6=9D=83=E9=99=90=E7=9A=84=E9=80=BB=E8=BE=91=E4=BB=8E?= =?UTF-8?q?demo=E9=87=8C=E7=A7=BB=E5=88=B0=E4=BA=86LBXScanViewController?= =?UTF-8?q?=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/LBXScanLineAnimation.swift | 2 +- Source/LBXScanNetAnimation.swift | 2 +- Source/LBXScanViewController.swift | 27 +++++++++-- Source/LBXScanViewStyle.swift | 2 +- Source/LBXScanWrapper.swift | 2 +- swiftScan/MainTableViewController.swift | 2 +- swiftScan/QQScanViewController.swift | 2 +- swiftScan/ViewController.swift | 62 +++++++++++-------------- 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/Source/LBXScanLineAnimation.swift b/Source/LBXScanLineAnimation.swift index 285cd9b..e1b2201 100644 --- a/Source/LBXScanLineAnimation.swift +++ b/Source/LBXScanLineAnimation.swift @@ -54,7 +54,7 @@ class LBXScanLineAnimation: UIImageView { self.frame = frame - }, completion: { (value: Bool) -> Void in + }, completion: { (_: Bool) -> Void in self.perform(#selector(LBXScanLineAnimation.stepAnimation), with: nil, afterDelay: 0.3) }) diff --git a/Source/LBXScanNetAnimation.swift b/Source/LBXScanNetAnimation.swift index 5df7ada..589a083 100644 --- a/Source/LBXScanNetAnimation.swift +++ b/Source/LBXScanNetAnimation.swift @@ -57,7 +57,7 @@ class LBXScanNetAnimation: UIImageView { self.frame = frame - }, completion: { (value: Bool) -> Void in + }, completion: { (_: Bool) -> Void in self.perform(#selector(LBXScanNetAnimation.stepAnimation), with: nil, afterDelay: 0.3) diff --git a/Source/LBXScanViewController.swift b/Source/LBXScanViewController.swift index c9ab4f0..48ce05e 100644 --- a/Source/LBXScanViewController.swift +++ b/Source/LBXScanViewController.swift @@ -41,6 +41,7 @@ open class LBXScanViewController: UIViewController, UIImagePickerControllerDeleg super.viewDidLoad() self.view.backgroundColor = UIColor.black self.edgesForExtendedLayout = UIRectEdge(rawValue: 0) + } open func setNeedCodeImage(needCodeImg: Bool) { @@ -61,8 +62,17 @@ open class LBXScanViewController: UIViewController, UIImagePickerControllerDeleg drawScanView() - perform(#selector(LBXScanViewController.startScan), with: nil, afterDelay: 0.3) - + LBXPermissions.authorizeCameraWith { (granted) in + if granted { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { + self.startScan() + }) + } else { + self.requireUserConfirmation { + LBXPermissions.jumpToSystemPrivacySetting() + } + } + } } @objc open func startScan() { @@ -141,7 +151,7 @@ open class LBXScanViewController: UIViewController, UIImagePickerControllerDeleg } open func openPhotoAlbum() { - LBXPermissions.authorizePhotoWith { [weak self] (granted) in + LBXPermissions.authorizePhotoWith { [weak self] (_) in let picker = UIImagePickerController() @@ -179,7 +189,7 @@ open class LBXScanViewController: UIViewController, UIImagePickerControllerDeleg func showMsg(title: String?, message: String?) { let alertController = UIAlertController(title: nil, message: message, preferredStyle: UIAlertControllerStyle.alert) - let alertAction = UIAlertAction(title: NSLocalizedString("OK", comment: "OK"), style: UIAlertActionStyle.default) { (alertAction) in + let alertAction = UIAlertAction(title: NSLocalizedString("OK", comment: "OK"), style: UIAlertActionStyle.default) { (_) in // if let strongSelf = self // { @@ -194,4 +204,13 @@ open class LBXScanViewController: UIViewController, UIImagePickerControllerDeleg // print("LBXScanViewController deinit") } + private func requireUserConfirmation(when confirmed: @escaping () -> Void) { + let alertController = UIAlertController(title: "去开启相机权限", message: nil, preferredStyle: UIAlertControllerStyle.alert) + alertController.addAction(UIAlertAction(title: "好的", style: UIAlertActionStyle.default, handler: { (_) in + confirmed() + })) + alertController.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.default, handler: nil)) + present(alertController, animated: true, completion: nil) + } + } diff --git a/Source/LBXScanViewStyle.swift b/Source/LBXScanViewStyle.swift index c2b53bd..f79c2fa 100644 --- a/Source/LBXScanViewStyle.swift +++ b/Source/LBXScanViewStyle.swift @@ -50,7 +50,7 @@ public struct LBXScanViewStyle { */ public var colorRetangleLine = UIColor.white - // MARK: -矩形框(扫码区域)周围4个角 + // MARK: - 矩形框(扫码区域)周围4个角 /** @brief 扫码区域的4个角类型 diff --git a/Source/LBXScanWrapper.swift b/Source/LBXScanWrapper.swift index 2cd14e1..ef94455 100644 --- a/Source/LBXScanWrapper.swift +++ b/Source/LBXScanWrapper.swift @@ -204,7 +204,7 @@ open class LBXScanWrapper: NSObject, AVCaptureMetadataOutputObjectsDelegate { open func captureImage() { let stillImageConnection: AVCaptureConnection? = connectionWithMediaType(mediaType: AVMediaType.video as AVMediaType, connections: (stillImageOutput?.connections)! as [AnyObject]) - stillImageOutput?.captureStillImageAsynchronously(from: stillImageConnection!, completionHandler: { (imageDataSampleBuffer, error) -> Void in + stillImageOutput?.captureStillImageAsynchronously(from: stillImageConnection!, completionHandler: { (imageDataSampleBuffer, _) -> Void in self.stop() if imageDataSampleBuffer != nil { diff --git a/swiftScan/MainTableViewController.swift b/swiftScan/MainTableViewController.swift index e3bdbbf..7a4b4b6 100644 --- a/swiftScan/MainTableViewController.swift +++ b/swiftScan/MainTableViewController.swift @@ -348,7 +348,7 @@ class MainTableViewController: UITableViewController, UIImagePickerControllerDel func showMsg(title: String?, message: String?) { let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) - let alertAction = UIAlertAction(title: "知道了", style: UIAlertActionStyle.default) { (alertAction) -> Void in + let alertAction = UIAlertAction(title: "知道了", style: UIAlertActionStyle.default) { (_) -> Void in } diff --git a/swiftScan/QQScanViewController.swift b/swiftScan/QQScanViewController.swift index a0151e1..ceea696 100644 --- a/swiftScan/QQScanViewController.swift +++ b/swiftScan/QQScanViewController.swift @@ -117,7 +117,7 @@ class QQScanViewController: LBXScanViewController { @objc func openLocalPhotoAlbum() { let alertController = UIAlertController(title: "title", message: "使用首页功能", preferredStyle: UIAlertControllerStyle.alert) - let alertAction = UIAlertAction(title: "知道了", style: UIAlertActionStyle.default) { (alertAction) -> Void in + let alertAction = UIAlertAction(title: "知道了", style: UIAlertActionStyle.default) { (_) -> Void in } diff --git a/swiftScan/ViewController.swift b/swiftScan/ViewController.swift index ef76f99..f7c79eb 100644 --- a/swiftScan/ViewController.swift +++ b/swiftScan/ViewController.swift @@ -56,41 +56,31 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour return } - LBXPermissions.authorizeCameraWith { [weak self] (granted) in - - if granted { - if let strongSelf = self { - - switch indexPath.row { - case 0: - strongSelf.qqStyle() - case 1: - strongSelf.ZhiFuBaoStyle() - case 2: - strongSelf.weixinStyle() - case 3: - strongSelf.InnerStyle() - case 4: - strongSelf.OnStyle() - case 5: - strongSelf.changeColor() - case 6: - strongSelf.recoCropRect() - case 7: - strongSelf.changeSize() - case 8: - strongSelf.notSquare() - case 9: - strongSelf.myCode() - case 10: - strongSelf.openLocalPhotoAlbum() - default: - break - } - } - } else { - LBXPermissions.jumpToSystemPrivacySetting() - } + switch indexPath.row { + case 0: + self.qqStyle() + case 1: + self.ZhiFuBaoStyle() + case 2: + self.weixinStyle() + case 3: + self.InnerStyle() + case 4: + self.OnStyle() + case 5: + self.changeColor() + case 6: + self.recoCropRect() + case 7: + self.changeSize() + case 8: + self.notSquare() + case 9: + self.myCode() + case 10: + self.openLocalPhotoAlbum() + default: + break } tableView.deselectRow(at: indexPath as IndexPath, animated: true) @@ -387,7 +377,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour func showMsg(title: String?, message: String?) { let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) - let alertAction = UIAlertAction(title: "知道了", style: UIAlertActionStyle.default) { (alertAction) -> Void in + let alertAction = UIAlertAction(title: "知道了", style: UIAlertActionStyle.default) { (_) -> Void in }