forked from happyboredom/Zbar-PhoneGap-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZbarPlug.m
61 lines (46 loc) · 1.9 KB
/
ZbarPlug.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// 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
{
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] presentModalViewController:reader animated:YES];
[reader release];
}
- (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;
NSString* retStr = [ NSString stringWithFormat:@"window.plugins.ZbarPlug.data = \"%@\";",
symbol.data];
[ webView stringByEvaluatingJavaScriptFromString:retStr ];
// if you need a javascript callback I would put it here (example)
// the callback can use the barcode data that was stored in window.plugins.ZbarPlug.data
// NSString* callbackStr = [ NSString stringWithFormat:@"window.plugins.ZbarPlug.finished_callback()"];
// this will execute the your javascript callback
//[ webView stringByEvaluatingJavaScriptFromString:callbackStr ];
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[[super appViewController] dismissModalViewControllerAnimated:YES];
}
@end