gpt4 book ai didi

ios - 使用 ZBar 阅读器时应用程序因内存压力而终止

转载 作者:行者123 更新时间:2023-11-29 03:05:29 30 4
gpt4 key购买 nike

我正在使用 ZBar reader在我的应用程序中扫描二维码。当我连续打开和关闭此扫描仪时,应用程序终止并显示消息由于内存压力而终止

我搜索了这个并得到了 answer我的应用程序面临同样的场景。即,第一次打开扫描仪有 1 秒的延迟,第二次有 2 秒的延迟,第三次有 5 秒的延迟。当进入第四或第五时,应用程序终止。

但这个答案是针对 UIImagePickerController 的。我正在使用 ZBar 阅读器。两者有些相似。我不知道如何修改我的代码来解决它。

这是我正在使用的代码,

codeReader = [ZBarReaderViewController new];
codeReader.readerDelegate=self;
codeReader.supportedOrientationsMask = ZBarOrientationMaskAll;
codeReader.showsCameraControls = NO;
codeReader.showsZBarControls=NO;
ZBarImageScanner *scanner = codeReader.scanner;
[scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch] || [device hasFlash]){
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
[device unlockForConfiguration];
}
}
[self.view.window.rootViewController presentViewController:codeReader animated:YES completion:nil];

codeReader.cameraOverlayView = overlayview;

我应该如何改变它来解决这个问题?

最佳答案

您可以创建 ZBar 阅读器的单个实例并将其存储为应用程序委托(delegate)上的属性,或者您可以使用 UIPickerController 答案中建议的单例方法。

在你的appDelegate.h中

@property(强,非原子)ZBarReaderViewController *zbarReaderVC;

在你的 appDelegate.m 中的 appDidFinishLaunching

self.zbarReaderVC = [ZBarReaderViewController new];
self.zbarReaderVC.readerDelegate=self;
self.zbarReaderVC.supportedOrientationsMask = ZBarOrientationMaskAll;
self.zbarReaderVC.showsCameraControls = NO;
self.zbarReaderVC.showsZBarControls=NO;
ZBarImageScanner *scanner = self.zbarReaderVC.scanner;
[scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch] || [device hasFlash]){
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
[device unlockForConfiguration];
}
}

然后每当您需要 View 时

MyAppDelegate *d=[UIApplication sharedApplication].delegate;

ZBarReaderViewController codeReader=d.zbarReaderVC;

[self.view.window.rootViewController presentViewController:codeReader animated:YES completion:nil];

codeReader.cameraOverlayView = overlayview;

完成后,将其从呈现 View Controller 中删除。

我还没有通读 ZBar reader 的文档,但是您可能需要调用一个方法来启动/停止它处理图像,即使它没有出现。我知道 ZXingObjC 有。

关于ios - 使用 ZBar 阅读器时应用程序因内存压力而终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828351/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com