2016-11-03 58 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; 
}