今天在做二维码的生成和读取图片中得二维码。一直报错:
BSXPCMessage received error for message: Connection interrupted
大意是:链接中断时,消息接收错误。
最后还是在stack overflow上面找到了答案。百度搜索就没有搜到中文的文章关于这个错误的。今天我就记录下来这个问题,供大家使用。
读取图片中得二维码代码;
- (void)readImage:(UIImage *)image{
CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
CIContext *context = [CIContext contextWithOptions:nil];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];
NSArray *features = [detector featuresInImage:ciImage];
NSLog(@"features = %@",features);
for (CIQRCodeFeature *feature in features) {
NSLog(@"msg = %@",feature.messageString);
}
}
首先说说
BSXPCMessage received error for message: Connection interrupted这个坑。
CIContext *context = [CIContext contextWithOptions:nil];
这里的参数里面传的nil,导致报错。解决办法;
把上面的代码改成:
CIContext *context = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}];
关于后面的是YES还是NO请自行解决。
好了上了的问题解决了。上面的方法还是不能读取图片中的二维码。
还有一个坑就是
CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
这一句,之前的写法是:
CIImage *ciImag = image.CIImage;
http://ask.csdn.net/questions/1876
有了上面的方法就可读取图片中得二维码了。