2016-11-03 102 views
1
let detector:CIDetector=CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])! 

它工作正常,在设备,但生成构建的iTunes分发时,它提供错误:CIDetectorTypeQRCode给出错误

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

如果我删除选项部分

[CIDetectorAccuracy:CIDetectorAccuracyHigh] 

然后它给错误,如:

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

有人对此有所了解吗?

我使用的是Swift 2.3和Xcode 8.1。

回答

3

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

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

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

+0

这也适用于我,我根本不明白... –

+0

非常有趣的技巧,它也解决了我的问题。 – bubuxu

-1

您好我也有同样的问题。我尝试了很多,但问题没有解决。后来我发现创建问题的编译器或swift语法。 所以创建了新的目标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; 
}