ios - Captuvo iPod 条码扫描器在 sleep 后显示不兼容的固件

标签 ios barcode-scanner

我正在尝试使用 Captuvo 条码扫描平台、Captuvo SDK 22 和 iOS 7 来实现一个小型 iPod 应用程序。该应用程序接收条码并将其发送到 WebView 。

应用程序的工作原理。我能够连接到设备并扫描条形码。

但是,在应用程序休眠(进入后台)后,在下次唤醒时,扫描器会失败并出现错误,提示“固件不兼容”。

奇怪的是,我可以退出该应用程序,然后重新启动它,并且设备会正常连接。

到目前为止,我最接近的尝试是在应用程序前台运行时尝试重新启动扫描仪,方法是:

UIApplicationWillEnterForegroundNotification

离工作太近了。这是我第一次尝试 iOS 开发,所以我可能遗漏了一些关于应用程序生命周期的基础知识。在官方 SDK 之外,关于如何对 Captuvo 进行编程的文档相对较少,因此我很想听听任何建议。

完整代码如下:

#import "MyViewController.h"
#import "Captuvo.h"

@interface MyViewController ()

@property (nonatomic, copy) NSString *barcode;    
@property (nonatomic, weak) IBOutlet UIWebView *webView;

@end

@implementation MyViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *strURL = @"http://myurl.com/scan.php";
    NSURL *url = [NSURL URLWithString:strURL];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:urlRequest];
}

- (void)viewWillAppear:(BOOL)animated
{
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleForeground)
                                                 name:UIApplicationWillEnterForegroundNotification object:nil];
}

-(void)handleForeground {
    [self.webView reload];
    [self initCaptuvoSDK];
}

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}

- (void)initCaptuvoSDK
{
    [[Captuvo sharedCaptuvoDevice] removeCaptuvoDelegate:self];
    [[Captuvo sharedCaptuvoDevice] addCaptuvoDelegate:self];
    [[Captuvo sharedCaptuvoDevice] startDecoderHardware];
    [[Captuvo sharedCaptuvoDevice] stopDecoderHardware];
    ProtocolConnectionStatus connectionStatus = [[Captuvo sharedCaptuvoDevice] startDecoderHardware];

    NSString *message;
    switch (connectionStatus) {
        case ProtocolConnectionStatusConnected:
            message = @"Connected!";
            break;
        case ProtocolConnectionStatusAlreadyConnected:
            message = @"Already Connected!";
            break;
        case ProtocolConnectionStatusBatteryDepleted:
            message = @"Battery depleted!";
            break;
        case ProtocolConnectionStatusUnableToConnect:
            message = @"Error connecting!";
            break;
        case ProtocolConnectionStatusUnableToConnectIncompatiableSledFirmware:
            message = @"Incompatible firmware!";
            break;
        default:
            message = @"Other!";
            break;
    }

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:message
                                                    message:message
                                                   delegate:self
                                          cancelButtonTitle:@"Okay"
                                          otherButtonTitles:@"Okay", nil];
    [alert show];
}

- (void)decoderReady
{
    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [[Captuvo sharedCaptuvoDevice] enableDecoderBeeperForGoodRead:YES persistSetting:NO] ;
        [[Captuvo sharedCaptuvoDevice]setDecoderSerialTriggerTimeoutInMilliSeconds:5000 persistSetting:NO];
    });
}

- (void)decoderDataReceived:(NSString *)data
{
    NSLog(@"decoderDataReceived");
    if(data != nil) {
        // send barcode to the webview
        NSString *str = [NSString stringWithFormat:@"processBarcode('%@');", data];
        [self.webView stringByEvaluatingJavaScriptFromString:str];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

最佳答案

我遇到了和你一样的问题。我修改了 AppDelegate.m 文件中的方法,如下所示。它对我有用。

-(void)applicationDidEnterBackground:(UIApplication *)application
{
    [[Captuvo sharedCaptuvoDevice] stopDecoderHardware];
}
-(void)applicationDidBecomeActive:(UIApplication *)application
{
    [[Captuvo sharedCaptuvoDevice] startDecoderHardware];
}

关于ios - Captuvo iPod 条码扫描器在 sleep 后显示不兼容的固件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23547551/

相关文章:

ios - JSONEncoder 去除尾随零

android - 将 ZXing 库直接集成到我的 Android 应用程序中

iphone - 如何使用phonegap 编译适用于iPhone 的条码扫描仪?

从外部蓝牙扫描仪捕获 iOS key 代码

ios - 如何设置不扭曲设备旋转的旋转变换?

ios - 更改 NavigationBar 人字形和标题颜色无效

ios - dismissViewControllerAnimated 不为 ViewController 设置动画

ios - 难以置备iPad应用程序以在iPad上进行测试

android - ZXing 无法读取 Android 应用中的一维条码

android - Android中如何获取iData(手机电脑iData95E)iScan条码图片?