【发布时间】:2015-10-09 21:34:30
【问题描述】:
我正在使用RSBarcodes for Swift 构建一个利用二维码扫描的应用程序。我在ScanViewController 中尝试做的是扫描二维码,验证扫描的内容,然后使用扫描的数据进行搜索。目前,当检测到二维码时,我的 UI 会冻结,并且在我收到错误和内存转储后不久:
'NSInternalInconsistencyException',原因:'只在主线程上运行!'。
也许这不是验证 QR 码的正确位置,或者不是进行转场的正确位置,但如果不是,我想知道应该在哪里进行验证和转场。我唯一的其他要求是仅在检测到 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
}
}
}
【问题讨论】:
标签: ios swift rsbarcodes