1
let detector:CIDetector=CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])!

它在设备中运行良好,但是在为 iTunes 分发生成构建时会出现错误:

“'[String:AnyObject] 类型的值?” 没有成员“钥匙”

如果我删除选项部分

[CIDetectorAccuracy:CIDetectorAccuracyHigh]

然后它给出如下错误:

(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector' 不能转换为 '(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector ?

有人对此有想法吗?

我正在使用 Swift 2.3 和 Xcode 8.1。

4

2 回答 2

3

我在 Swift 3 和 XCode 8.1 中遇到了同样的问题

下面是我的解决方案。将 CIDetector(...) 更改为 CIDetector.init(...)

let detector: CIDetector? = CIDetector.init(ofType:CIDetectorTypeQRCode, context:nil, options:[CIDetectorAccuracy: CIDetectorAccuracyHigh])

于 2016-11-07T10:31:46.573 回答
-1

你好我也有同样的问题。我尝试了很多,但问题没有解决。后来我发现编译器或快速语法创建了问题。所以创建了新的目标 c 文件,在那里添加了目标代码并且它起作用了。所以尝试使用目标 c 文件。这真的对我有用。

-(NSString *)getQRCodeStringFromImage:(UIImage *)QRcodeimage {

    NSDictionary *detectorOptions = @{@"CIDetectorAccuracy": @"CIDetectorAccuracyHigh"};
    CIDetector *detector = [CIDetector  detectorOfType:CIDetectorTypeQRCode context:nil options:detectorOptions];
    CIImage *ciImage = [[CIImage alloc] initWithImage:QRcodeimage];

    if (detector)  {

        NSArray* featuresR = [detector featuresInImage:ciImage];
        NSString* decodeR;

        for (CIQRCodeFeature* featureR in featuresR)  {
            decodeR = featureR.messageString;
        }
        NSLog(@"QRCode String : %@" , decodeR);

        return decodeR;
    }
    return  nil;
}
于 2016-11-18T13:57:11.527 回答