I have eventually embedded zbarsdk into my app without error message. However, I found a new issue. I need to open url that will be collected from qrcode to a webviewcontroller. The problem is that after the scanning, the result ether appear too late (it takes long to appear) or fall to appear, and sometime even show previous result (website). This is my codes in .h
#import <UIKit/UIKit.h>
#import "ZBarSDK.h"
@interface QR_ReaderViewController : UIViewController <ZBarReaderDelegate>{
}
@property (weak, nonatomic) IBOutlet UIWebView *webView1;
@end
and .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
Am I do something wrong?
It seems you have put webview result code
at wrong place.. Try below code.. It might solve your problems
- (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];
}