【发布时间】:2014-12-15 10:43:19
【问题描述】:
我使用 ZXING 为 Android 开发了一个 DataMatrix Reader,并且工作正常,现在我正在使用 iOS 版本,但是当我想在我的项目中使用该库时出现此错误:
iOS SDK 8.1 和库 ZXING:https://github.com/TheLevelUp/ZXingObjC
我用的是 COCOAPODS:
平台:ios,'7.0' pod 'ZXingObjC', '~> 3.0'
我在我的项目中使用 Cocoapods 实现了这个库,现在我想在我的应用程序中这样使用:
#import "ViewController.h"
#import "ZXingObjC.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)scanBarcode:(id)sender {
CGImageRef imageToDecode; // Given a CGImage in which we are looking for barcodes
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
ZXBinaryBitmap *bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];
NSError *error = nil;
// There are a number of hints we can give to the reader, including
// possible formats, allowed lengths, and the string encoding.
ZXDecodeHints *hints = [ZXDecodeHints hints];
ZXMultiFormatReader *reader = [ZXMultiFormatReader reader];
ZXResult *result = [reader decode:bitmap
hints:hints
error:&error];
if (result) {
// The coded result as a string. The raw data can be accessed with
// result.rawBytes and result.length.
NSString *contents = result.text;
// The barcode format, such as a QR code or UPC-A
ZXBarcodeFormat format = result.barcodeFormat;
} else {
// Use error to determine why we didn't get a result, such as a barcode
// not being found, an invalid checksum, or a format inconsistency.
}
}
@end
但我有这个错误:
DataMatrixReader/ViewController.m:32:99:ARC 禁止显式消息 发送“自动释放”
DataMatrixReader/ViewController.m:32:99:“自动释放”不可用: 在自动引用计数模式下不可用
具体在这一行:
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
来自 "iamnichols" 的帮助...在换行之后:
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
到
ZXLuminanceSource *source = [[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode];
错误:
:CGBitmapContextGetData:无效的上下文 0x0。这是一个 严重错误。此应用程序或它使用的库正在使用 无效的上下文,从而导致整体退化 系统的稳定性和可靠性。此通知是一种礼貌:请 解决这个问题。这将成为即将到来的更新中的致命错误。 2014-12-15 12:12:36.122 DataMatrixReader[18838:412778] * 终止 应用程序由于未捕获的异常“NSInvalidArgumentException”,原因: '两个维度都必须大于 0' * 第一次抛出调用堆栈:( 0 CoreFoundation 0x0000000102626f35 exceptionPreprocess + 165 1 libobjc.A.dylib
0x00000001022bfbb7 objc_exception_throw + 45 2 DataMatrixReader
0x0000000100f09507 -[ZXBitMatrix initWithWidth:height:] + 231 3
DataMatrixReader 0x0000000100f51b7d -[ZXGlobalHistogramBinarizer blackMatrixWithError:] + 141 4 DataMatrixReader 0x0000000100f530b0 -[ZXHybridBinarizer blackMatrixWithError:] + 816 5 DataMatrixReader 0x0000000100f068ab -[ZXBinaryBitmap blackMatrixWithError:] + 139 6
DataMatrixReader 0x0000000100fa43b2 -[ZXQRCodeReader decode:hints:error:] + 130 7 DataMatrixReader 0x0000000100f63d04 -[ZXMultiFormatReader decodeInternal:error:] + 548 8 数据矩阵读取器 0x0000000100f62ade -[ZXMultiFormatReader decode:hints:error:] + 142 9 DataMatrixReader 0x0000000100ef1df2 -[ViewController scanBarcode:] + 322 10 UIKit
0x0000000102a148be -[UIApplication sendAction:to:from:forEvent:] + 75 11 UIKit 0x0000000102b1b410 -[UIControl _sendActionsForEvents:withEvent:] + 467 12 UIKit 0x0000000102b1a7df -[UIControl touchesEnded:withEvent:] + 522 13 UIKit 0x0000000102a5a308 -[UIWindow _sendTouchesForEvent:] + 735 14 UIKit 0x0000000102a5ac33 -[UIWindow sendEvent:] + 683 15 UIKit
0x0000000102a279b1 -[UIApplication sendEvent:] + 246 16 UIKit
0x0000000102a34a7d _UIApplicationHandleEventFromQueueEvent + 17370 17 UIKit 0x0000000102a10103 _UIApplicationHandleEventQueue + 1961 18 核心基础 0x000000010255c551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 19 核心基础 0x000000010255241d __CFRunLoopDoSources0 + 269 20 CoreFoundation 0x0000000102551a54 __CFRunLoopRun + 868 21 CoreFoundation
0x0000000102551486 CFRunLoopRunSpecific + 470 22 图形服务
0x0000000104bc09f0 GSEventRunModal + 161 23 UIKit
0x0000000102a13420 UIApplicationMain + 1282 24 DataMatrixReader
0x0000000100ef2343 main + 115 25 libdyld.dylib
0x00000001058a3145 start + 1 ) libc++abi.dylib: 终止于 NSException (lldb) 类型的未捕获异常
现在的问题是有人试图将 ZxingObjC 集成到 iOS 8.1 中?
【问题讨论】:
-
你真的看过错误信息吗?
-
是的,但是现在我有另一个之后来实现该行以避免最后一个错误。
-
第二个错误可能是因为
imageToDecode是NULL。这段代码是您自己编写的,还是您只是从互联网上复制下来并希望它能够正常工作? -
SO 不是调试服务。如果您不知道自己在这里做什么,也许您需要停止使用第三方库
-
这是ZXingObjC的官方git一步一步的,代码是从这个网站复制/粘贴的,这是一个普遍的问题,我知道SO不是调试服务,但我猜是一个帮助人们的地方,并且为了解释问题需要粘贴日志,在这种情况下,在开源 Barcodes SDK 中不存在更多在 iOS 中解码 DataMatrix 的可能性,如果我能解决这个问题,可能还有其他人在同样的问题可以解决问题,这就是SO的哲学。
标签: ios objective-c ios8 automatic-ref-counting zxing