Swift:不pipe我做什么CIDetector总是零

我不明白为什么这个代码不起作用,探测器总是为零,CIDetectorTypeQRCode为常量,一切都与CIDetectorTypeFace一起工作。 我从苹果的API的一个错误。 这是官方文档: 苹果文档

@IBAction func analyseTag(sender: AnyObject) { var detector:CIDetector = CIDetector(ofType: CIDetectorTypeQRCode, context:nil, options:[CIDetectorAccuracy: CIDetectorAccuracyHigh]) var decode = "" var ciImage:CIImage = CIImage(image: ImgChoosed.image) var message:String = ""; let features = detector.featuresInImage(ciImage) for feature in features as [CIQRCodeFeature] { message += feature.messageString } if(message == "") { println("nothing") } else { println("\(message)") } } 

你有解决scheme吗? 先谢谢你了

这也发生在我们身上。 iPhone 4s不返回QRCodetypes的CIDetector。 其他types(矩形,脸)虽然工作…

相同的代码在iPhone 6上的预期工作。还没有testing5或5s。

但两个星期前,我相信还是在4s上工作。 我猜,当时还是在iOS 8上。

你提供的代码不能有一个零detector因为它不是一个可选的,编译器会抱怨代码中的几个地方。

如果function是空的,那么你知道它没有在你的图像中findQR码。 尝试提供更好的图像或closuresCIDetectorAccuracy

如果function不是空的,那么你的演员失败。

编辑:你不能在构造函数中传递一个nil上下文。

  1. 确保你的ImgChoosed.image不是零。
  2. 更改另一个input图像进行testing。
  3. 尝试for feature in features as! [CIQRCodeFeature] for feature in features as! [CIQRCodeFeature]

我发现在设备上使用解决了这个问题。 模拟器似乎总是返回零。