您的位置:首页 > 移动开发 > IOS开发

iOS 读取相册二维码

2017-06-22 11:58 267 查看
   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这个库才行哦.


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息