Reputation: 4386
I have the following code perfectly working, except ... well for the call back !
- (void)readBarcode:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_EAN13
config: ZBAR_CFG_ENABLE
to: 1];
[[super appViewController] presentModalViewController:reader animated:YES];
[reader release];
}
(void) imagePickerController:(UIImagePickerController*)reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
resultText.text = symbol.data;
resultImage.image = [info objectForKey: UIImagePickerControllerOriginalImage];
NSString* retStr = [[NSString alloc]
initWithFormat:@"%@({ code: '%@', image: '%@' });",
resultText.text,resultImage.image];
[ webView stringByEvaluatingJavaScriptFromString:retStr ];
[reader dismissModalViewControllerAnimated: YES];
}
I then call the function from javascript :
function getIt(){
PhoneGap.exec("BarcodeReader.readBarcode", "myCallback");
}
Problem is that I don't understand how to call the 'myCallBack' function from c# (admit i'm a total newbie)
Upvotes: 0
Views: 2759
Reputation: 33345
This should work...
Add property to header file ( How To Add A Property In Objective C )
-(NSString *) jsCallback;
Get the javascript callback method and set the property
- (void)readBarcode:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
// New Property added !!!!
NSString * jsCallback = [info objectAtIndex:0];
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_EAN13
config: ZBAR_CFG_ENABLE
to: 1];
[[super appViewController] presentModalViewController:reader animated:YES];
[reader release];
}
Use the javascript callback method here
- (void) imagePickerController:(UIImagePickerController*)reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
resultText.text = symbol.data;
resultImage.image = [info objectForKey: UIImagePickerControllerOriginalImage];
// create the string
NSString* retStr = [[NSString alloc]
initWithFormat:@"%@({ code: '%@', image: '%@' });",
jsCallback,resultText.text,resultImage.image];
//execute
[ webView stringByEvaluatingJavaScriptFromString:retStr ];
[reader dismissModalViewControllerAnimated: YES];
}
Please mark the other answer I provided you as correct also
Upvotes: 1