iOS 读取相册二维码

   iOS读取相册二维码请使用官方的方法.现在开始练习起来.

func beginQRImage(image:UIImage) -> Void {
        
        let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh]);

        let url = URL(fileURLWithPath: Bundle.main.path(forResource: "timg", ofType: "jpeg")!);
        let ciImage = CIImage(contentsOf: url);
        
        let feature = detector?.features(in: ciImage!);
        
        for item in feature! {
            print("type = \(item.type)");
            if let qrFeature = item as? CIQRCodeFeature {
                print(qrFeature.messageString);
            }
            
        }
        
    }

  就这个以方法就可了.

 哦哦,忘了说一下,需要导入CoreImage这个库才行哦.




你可能感兴趣的:(iOS,swift,二维码,读取二维码,swift,swift新特性,原生二维码,二维码,swift,ios)