Skip to content

Commit

Permalink
Merge pull request #63 from dvlprliu/master
Browse files Browse the repository at this point in the history
fix: 把请求相机权限的逻辑从demo里移到了LBXScanViewController里
  • Loading branch information
MxABC authored Sep 4, 2018
2 parents 2469ba8 + f6d11ec commit ea33c72
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Source/LBXScanLineAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion Source/LBXScanNetAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 23 additions & 4 deletions Source/LBXScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
// {
Expand All @@ -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)
}

}
2 changes: 1 addition & 1 deletion Source/LBXScanViewStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct LBXScanViewStyle {
*/
public var colorRetangleLine = UIColor.white

// MARK: -矩形框(扫码区域)周围4个角
// MARK: - 矩形框(扫码区域)周围4个角

/**
@brief 扫码区域的4个角类型
Expand Down
2 changes: 1 addition & 1 deletion Source/LBXScanWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion swiftScan/MainTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down
2 changes: 1 addition & 1 deletion swiftScan/QQScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down
62 changes: 26 additions & 36 deletions swiftScan/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

}

Expand Down

0 comments on commit ea33c72

Please sign in to comment.