forked from happyboredom/Zbar-PhoneGap-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ZbarPlug.m
70 lines (51 loc) · 1.92 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
60
61
62
63
64
65
66
67
68
//
// 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
@synthesize callback;
- (void)showZbar:(NSArray*)arguments withDict:(NSDictionary*)options
{
NSUInteger argc = [arguments count];
self.callback = nil;
if (argc > 0) {
self.callback = [arguments objectAtIndex:0];
//[self.callback retain];
}
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;
// this will execute the your javascript callback
[ webView stringByEvaluatingJavaScriptFromString: [NSString stringWithFormat:@"%@({value:\"%@\", type:\"%@\"});", self.callback, symbol.data, symbol.typeName ]];
//[self.callback release];
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[[super appViewController] dismissModalViewControllerAnimated:YES];
// reset position
// you don't have to do that if you hide the status bar
webView.frame = CGRectMake(webView.frame.origin.x, 20, webView.frame.size.width, webView.frame.size.height);
}
@end