我正在为我们的本地企业开发一个应用程序。我已经在 a 中安装了实时摄像头UIImageView
,现在我需要知道如何读取 QR 码UIImageView
并在标签中显示内容 (0000-KKP0-2013)。
所以基本上我需要一个二维码扫描仪来读取二维码并将内容保存在字符串中。我已经使用过 ZXing(“斑马线”),但它与 iOS 6 不兼容,无法使用。是否有一个简单的代码来获取字符串中的二维码内容?
谢谢!
这是我在 .m 文件中使用的代码:
#import "ZBarSDK.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize vImagePreview;
- (void)viewDidUnload
{
[super viewDidUnload];
vImagePreview = nil;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//----- SHOW LIVE CAMERA PREVIEW -----
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPreset352x288;
/*CALayer *viewLayer = self.vImagePreview.layer;
NSLog(@"viewLayer = %@", viewLayer);*/
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
AVCaptureDevice *device = [self frontCamera];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"QReader"
message:[NSString stringWithFormat:@"ERROR: Versuch die Kamera zu öffnen ist fehlgeschlagen [%@]",error]
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.tag = 1;
[alert show];
}
[session addInput:input];
[session startRunning];
}
- (AVCaptureDevice *)frontCamera {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device position] == AVCaptureDevicePositionFront) {
return device;
}
}
return nil;
}
现在我需要知道如何使用 ZBarSDK 从 vImagePreview 读取 QR 码。而且我不能使用 UIPickerView