我使用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禁止显式消息 发送' autorelease'
DataMatrixReader / ViewController.m:32:99:' autorelease'不可用: 不适用于自动参考计数模式
具体地说:
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:提示:错误:] + 130 7 DataMatrixReader 0x0000000100f63d04 - [ZXMultiFormatReader decodeInternal:错误:] + 548 8 DataMatrixReader 0x0000000100f62ade - [ZXMultiFormatReader decode:提示:错误:] + 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 CoreFoundation 0x000000010255c551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 19 CoreFoundation 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中吗?
答案 0 :(得分:2)
我认为您的项目使用ARC但ZXING库不是。在这种情况下,请转到路径'目标 - >构建阶段 - >在ZXING库中编译源代码。双击每个.m文件,在弹出的对话框中输入“-fno-objc-arc”。这样,这些文件将被排除在ARC
之外答案 1 :(得分:0)
如果您的项目正在使用ARC(自动参考计数),那么您就不需要进行autorelease
次呼叫。
更改
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
到
ZXLuminanceSource *source = [[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode];
有关ARC的更多信息,请参阅iOS Developer Library
答案 2 :(得分:0)
这对我很有用:
readme.md中的入门不起作用,因此我必须执行以下步骤才能使其正常工作。
将整个文件夹复制到工作项目的子文件夹中。
并将ZXingObjC.xcodeproj文件拖放/添加到“<your working project>”
。
确保在提示时勾选create folder references for any added folders
选项。
然后,转到你的项目目标&gt;建立阶段
,add ZXingObjC-iOS (ZXingObjC)
在Link Binary With Libraries下,add libZXingObjC-iOS.a
在同一类别下,添加以下6个框架
AVFoundation.framework
CoreGraphics.framework
CoreMedia.framework
CoreVideo.framework
ImageIO.framework
QuartzCore.framework
我在直接设备Iphone 4s上的测试很好,也许不是最好的测试设备,Iphone 4s没有“AutoFocus”功能,对于使用这个条形码非常重要。
希望这可以节省你的一天。