Zbarsdk无法正确实现webviewcontroller

时间:2014-02-05 04:21:43

标签: iphone objective-c zbar-sdk

我最终将zbarsdk嵌入到我的应用中,没有出现错误消息。但是,我发现了一个新问题。我需要打开将从qrcode收集到webviewcontroller的url。问题是在扫描之后,结果以太出现(出现需要很长时间)或出现下降,有时甚至显示以前的结果(网站)。这是我的代码.h

#import <UIKit/UIKit.h>
#import "ZBarSDK.h"

@interface QR_ReaderViewController : UIViewController <ZBarReaderDelegate>{
}

@property (weak, nonatomic) IBOutlet UIWebView *webView1;
@end

和.m

#import "QR_ReaderViewController.h"

@interface QR_ReaderViewController ()
@end

@implementation QR_ReaderViewController

NSString *resultText;

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
    self.title = @"QR Reader";

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
return self;
}

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

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

- (void)viewDidLoad {
[super viewDidLoad];

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
[reader.scanner setSymbology: ZBAR_UPCA config: ZBAR_CFG_ENABLE to: 0];
reader.readerView.zoom = 1.0;
[self presentViewController:reader animated:YES completion:nil];

//webview result
NSURL *url = [NSURL URLWithString:resultText];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView1 loadRequest: requestObj];
}

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id <NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)

    break;

resultText = symbol.data;

[reader dismissViewControllerAnimated:YES completion:nil];
}

+ (NSString*) getResultText
{
return resultText;
}

@end

我做错了吗?

1 个答案:

答案 0 :(得分:1)

您似乎已将webview result code放在错误的位置。请尝试以下代码..它可能会解决您的问题

- (void)viewDidLoad {
    [super viewDidLoad];
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    [reader.scanner setSymbology: ZBAR_UPCA config: ZBAR_CFG_ENABLE to: 0];
    reader.readerView.zoom = 1.0;
    [self presentViewController:reader animated:YES completion:nil];
}

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
    {
    id <NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)

        break;

    resultText = symbol.data;

   //webview result and Solution of showing Previous Result
   NSURL *url = [NSURL URLWithString:resultText];
   NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
   [_webView1 loadRequest: requestObj];

  // To Overcome Delay  
  if (![reader isBeingPresented]) {
        [self dismissReader:reader];
       }
       else{
         [self performSelector:@selector(dismissReader:) withObject:reader afterDelay:0.7];
       }
    }


 - (void) dismissReader:(UIImagePickerController*) reader
  {
     [reader dismissViewControllerAnimated:YES completion:nil];
  }