Swfit3.0 实现扫描二维码 , 不走代理方法或者是没有扫描到数据? 财富值91

2016-10-19 17:35发布

//  输入设备     fileprivate lazy var input: AVCaptureDeviceInput? = {         let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)         return try? AVCaptureDeviceInput(device: device)     }()     // 输出对象     fileprivate lazy var output : AVCaptureMetadataOutput = {         let output = AVCaptureMetadataOutput()         output.metadataObjectTypes = output.availableMetadataObjectTypes         output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)         let centerViewFrame = self.centerView.frame         let screenFrame = UIScreen.main.bounds         // 测试发现系统是按照右上角作为参照, 并不是以左上角         let x = centerViewFrame.origin.y / screenFrame.size.height         let y = centerViewFrame.origin.x / screenFrame.size.width         let width = centerViewFrame.size.height / screenFrame.size.height         let height = centerViewFrame.size.width / screenFrame.size.width         output.rectOfInterest = CGRect(x: x, y: y, width: width, height: height)         return output     }()     // 会话     fileprivate lazy var session = AVCaptureSession()     // 预览图层     fileprivate lazy var previewlayer: AVCaptureVideoPreviewLayer = {         let layer = AVCaptureVideoPreviewLayer(session: self.session)         layer?.frame = self.view.bounds         return layer!     }() 
// MARK: - 二维码扫描 extension QRCodeViewController: AVCaptureMetadataOutputObjectsDelegate {     fileprivate func setupScanQRCode() {         if !session.canAddInput(input) || !session.canAddOutput(output) {             return         }         session.addInput(input)         session.addOutput(output)         view.layer.insertSublayer(previewlayer, at: 0)         session.startRunning()     }     func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {         for objc in metadataObjects {             let tempObjc = objc as! AVMetadataMachineReadableCodeObject             CCLog(tempObjc.stringValue)         }     } }

不走后面的代理方法, 如果是因为没有扫描到数据而没有走代理方法, 那这里写的有什么问题吗? 望指出

友情提示: 问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
0条回答

一周热门 更多>