我正在使用QRcode创建一个应用程序,我有一个使用条形码扫描仪的先前代码。可以将其修改为QRcode扫描仪吗?
由于
答案 0 :(得分:1)
CIdetector type: CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
将CIdetector类型更改为CIDetectorTypeQRCode。
答案 1 :(得分:1)
要扫描条形码和qrcode,您可以使用下面的代码段
在视图控制器中添加它
as.Date
然后在viewcontroller中添加此函数
p2p_dt_SKILL_A%>%
select(Patch,Date,Prod_DL)%>%
filter(between(Date, as.Date("2015-09-05"),as.Date("2015-09-17")))
然后在let supportedCodeTypes = [AVMetadataObjectTypeUPCECode,
AVMetadataObjectTypeCode39Code,
AVMetadataObjectTypeCode39Mod43Code,
AVMetadataObjectTypeCode93Code,
AVMetadataObjectTypeCode128Code,
AVMetadataObjectTypeEAN8Code,
AVMetadataObjectTypeEAN13Code,
AVMetadataObjectTypeAztecCode,
AVMetadataObjectTypePDF417Code,
AVMetadataObjectTypeQRCode]
func startVideoCapture(){
// Get an instance of the AVCaptureDevice class to initialize a device object and provide the video as the media type parameter.
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
do {
// Get an instance of the AVCaptureDeviceInput class using the previous device object.
let input = try AVCaptureDeviceInput(device: captureDevice)
// Initialize the captureSession object.
captureSession = AVCaptureSession()
// Set the input device on the capture session.
captureSession?.addInput(input)
// Initialize a AVCaptureMetadataOutput object and set it as the output device to the capture session.
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
// Set delegate and use the default dispatch queue to execute the call back
captureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
captureMetadataOutput.metadataObjectTypes = supportedCodeTypes
// Initialize the video preview layer and add it as a sublayer to the viewPreview view's layer.
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
videoPreviewLayer?.frame = self.qrCodeView.bounds
self.qrCodeView.layer.addSublayer(videoPreviewLayer!)
self.qrCodeView.clipsToBounds = true
// Start video capture.
captureSession?.startRunning()
qrCodeFrameView = UIView()
// if let qrCodeFrameView = qrCodeFrameView {
// qrCodeFrameView.layer.borderColor = UIColor.green.cgColor
// qrCodeFrameView.layer.borderWidth = 2
// self.qrCodeView.addSubview(qrCodeFrameView)
// self.qrCodeView.bringSubview(toFront: qrCodeFrameView)
// }
} catch {
// If any error occurs, simply print it out and don't continue any more.
print(error)
return
}
}
并且在调用startVideoCapture
之前不要忘记检查相机权限