Reputation: 9
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.
Upvotes: 1
Views: 496
Reputation: 9
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;
}
Upvotes: -1
Reputation: 89
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])
Upvotes: 3