- (void)qrScan:(UIImage *)image{
CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
CIContext *context = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}]; // 渲染
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 识别
// 注意这里的CIDetectorTypeQRCode
NSArray *features = [detector featuresInImage:ciImage];
NSLog(@"features = %@",features); // 识别后的结果
for (CIQRCodeFeature *feature in features) {
NSLog(@"msg = %@",feature.messageString); // 打印二维码中的信息
//根据自己的需求对str做处理
NSString *str = [NSString stringWithFormat:@"%@",feature.messageString];
if ([str hasPrefix:@"http://"]||[str hasPrefix:@"https://"]) {//调到safari浏览器
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
} }
}