Skip to content

Instantly share code, notes, and snippets.

@philippeowagner
Forked from happyboredom/ZbarPhoneGap.h
Created December 15, 2010 21:24
Show Gist options
  • Select an option

  • Save philippeowagner/742630 to your computer and use it in GitHub Desktop.

Select an option

Save philippeowagner/742630 to your computer and use it in GitHub Desktop.
function onBodyLoad()
{
// this is standard with phonegap. body onload="onBodyLoad()"
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady()
{
// once device is ready, you can execute Zbar.
// this fires the Obj-C directly. I am trying to figure out the JS layer.
PhoneGap.exec("ZbarPlug.showZbar");
}
//
// ZbarPlug.h
// Phun
//
// Created by Jeff Lee on 12/12/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PhoneGapCommand.h"
#import "ZBarSDK.h"
@interface ZbarPlug : PhoneGapCommand <ZBarReaderViewDelegate>
{
}
- (void)showZbar:(NSArray*)arguments withDict:(NSDictionary*)options;
@end
function ZbarPlug() {
}
ZbarPlug.prototype.getQrCode = function () {
PhoneGap.exec("ZbarPlug.showZbar");
};
PhoneGap.addConstructor( function ()
{
if (typeof window.plugins == 'undefined')
window.plugins = {};
if( typeof window.plugins.ZbarPlug == 'undefined' )
window.plugins.ZbarPlug = new ZbarPlug();
});
//
// ZbarPlug.m
// Phun
//
// Created by Jeff Lee on 12/12/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "ZbarPlug.h"
@implementation ZbarPlug
- (void)showZbar:(NSArray*)arguments withDict:(NSDictionary*)options
{
// Zbar provides you a fully functional UI that automatically scans!
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
// [super appViewController] piece is where the magic happens
// PhoneGap will pass control and open the Zbar scanner!
[[super appViewController] presentModalViewController:reader animated:YES];
[reader release];
}
// This is inherited from the ZBarReaderViewDelegate
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
//UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// This is where the magic happens to send back the
// decoded information to PhoneGap.
NSString* retStr = [ NSString stringWithFormat:@"alert(\"%@\");", symbol.data];
[ webView stringByEvaluatingJavaScriptFromString:retStr ];
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[[super appViewController] dismissModalViewControllerAnimated:YES];
}
@end
@RajaramMohanty
Copy link
Copy Markdown

Wht is the index.Html file pls send me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment