CIDetectorTypeQRCode gives error

只谈情不闲聊 提交于 2020-01-05 04:14:32

问题


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

It works fine in device but when generating build for iTunes distribution it gives error:

"Value of type '[String:AnyObject]?" has no member 'Key'

If I remove the option part

[CIDetectorAccuracy:CIDetectorAccuracyHigh]

then it gives error like:

(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector' is not convertible to '(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector?'

Anyone have idea about this?

I am using Swift 2.3 and Xcode 8.1.


回答1:


I got same issue in Swift 3 and XCode 8.1

Below is my solution. Change CIDetector(...) to CIDetector.init(...)

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




回答2:


Hi I also have this same problem. I tried a lot but the issue was not resolving. Later I found that the compiler or swift syntax creating creating the problem. So Created new objective c files, Added objective code there and it worked. So try with objective c file. This really worked for me.

-(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;
}


来源:https://stackoverflow.com/questions/40409417/cidetectortypeqrcode-gives-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!