ios – 使用RSBarcodes扫描条形码时执行 *** 作

ios – 使用RSBarcodes扫描条形码时执行 *** 作,第1张

概述我正在使用 RSBarcodes for Swift构建一个利用QR码扫描的应用程序.我在ScanViewController中尝试做的是扫描QR码,验证扫描内容,然后扫描扫描数据.目前,当检测到QR代码时,我的UI冻结,并且在我收到错误和内存转储后不久: ‘NSInternalInconsistencyException’, reason: ‘Only run on the main threa 我正在使用 RSBarcodes for Swift构建一个利用QR码扫描的应用程序.我在ScanVIEwController中尝试做的是扫描QR码,验证扫描内容,然后扫描扫描数据.目前,当检测到QR代码时,我的UI冻结,并且在我收到错误和内存转储后不久:

‘NSInternalinconsistencyException’,reason: ‘Only run on the main thread!’.

也许这不是验证QR码的正确位置,或者不适合segue,但如果没有,我想知道验证和segue应该在哪里进行.我唯一的另一个要求是验证仅在检测到QR码时才会发生.

class ScanVIEwController: RSCodeReaderVIEwController{    // Class Variables    var finalObject: IBuiltCode?    let ObjectHelper = ObjectBuilder() // Service to valIDate and build valID scanned objects    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        self.focusMarkLayer.strokecolor = UIcolor.redcolor().CGcolor        self.cornersLayer.strokecolor = UIcolor.yellowcolor().CGcolor        self.tapHandler = { point in            println(point)        }        self.barcodesHandler = { barcodes in            for barcode in barcodes {                println("barcode found: type=" + barcode.type + " value=" + barcode.stringValue)                if let builtObject = self.ObjectHelper.valIDateAndBuild(barcode,scannedData: barcode.stringValue){                    println("Good object.")                    self.performQR()                }            }        }    }    func performQR(){        performSegueWithIDentifIEr("toQR",sender: self)    }    overrIDe func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) {        if (segue.IDentifIEr == "toQR"){            let QRVC: QRVIEwController = segue.destinationVIEwController as! QRVIEwController            QRVC.receivedobject = finalObject as? QRObject        }    }}
@R_404_6120@ 我在 this issue线程上联系了RSbarcodes_Swift的开发人员.为了执行任何UI *** 作,需要在主线程上运行.例如,需要更改segue函数:

func performQR(){        self.performSegueWithIDentifIEr("toQR",sender: self)}

func performQR(){    dispatch_async(dispatch_get_main_queue(),{ () -> VoID in        self.performSegueWithIDentifIEr("toQR",sender: self)    })}

为了避免在扫描时多次进行segueing,可以在条形码for循环中使用调用self.session.stopRunning()和breakcan.

self.barcodesHandler = { barcodes in    for barcode in barcodes {        println("barcode found: type=" + barcode.type + " value=" + barcode.stringValue)        if let builtObject = self.ObjectHelper.valIDateAndBuild(barcode,scannedData: barcode.stringValue){            println("Good object.")            self.finalObject = builtObject            self.session.stopRunning() // AvoID scanning multiple times            self.performQR()            break        }    }}
总结

以上是内存溢出为你收集整理的ios – 使用RSBarcodes扫描条形码时执行 *** 作全部内容,希望文章能够帮你解决ios – 使用RSBarcodes扫描条形码时执行 *** 作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1077460.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存