【iOS】BSXPCMessage received error for message: Connection interrupted的解决办法

今天在做二维码的生成和读取图片中得二维码。一直报错:

 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,导致报错。解决办法;

http://stackoverflow.com/questions/26163018/bsxpcmessage-received-error-for-message-connection-interrupted-on-cicontext-wit

把上面的代码改成:

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

导致不能得到CIImage对象。

有了上面的方法就可读取图片中得二维码了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值