From d8607102f76ef594aaf4283a75b1d8430f9b383a Mon Sep 17 00:00:00 2001 From: Philip Majewski Date: Wed, 22 May 2013 14:56:57 +0200 Subject: [PATCH 1/3] Updated to current Cordova API --- iPhone/BarcodeScanner/PGBarcodeScanner.mm | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/iPhone/BarcodeScanner/PGBarcodeScanner.mm b/iPhone/BarcodeScanner/PGBarcodeScanner.mm index 752e294c..cf2830d1 100644 --- a/iPhone/BarcodeScanner/PGBarcodeScanner.mm +++ b/iPhone/BarcodeScanner/PGBarcodeScanner.mm @@ -16,11 +16,8 @@ //------------------------------------------------------------------------------ #import "zxing-all-in-one.h" -#ifdef PHONEGAP_FRAMEWORK -#import -#else -#import "PGPlugin.h" -#endif +#import + //------------------------------------------------------------------------------ // Adds a shutter button to the UI, and changes the scan from continuous to @@ -35,7 +32,7 @@ //------------------------------------------------------------------------------ // plugin class //------------------------------------------------------------------------------ -@interface PGBarcodeScanner : PGPlugin {} +@interface PGBarcodeScanner : CDVPlugin {} - (NSString*)isScanNotPossible; - (void)scan:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; - (void)encode:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; @@ -132,7 +129,7 @@ - (void)scan:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { processor = [[PGbcsProcessor alloc] initWithPlugin:self callback:callback - parentViewController:[self appViewController] + parentViewController:[self viewController] alterateOverlayXib:overlayXib ]; @@ -154,8 +151,8 @@ - (void)returnSuccess:(NSString*)scannedText format:(NSString*)format cancelled: [resultDict setObject:format forKey:@"format"]; [resultDict setObject:cancelledNumber forKey:@"cancelled"]; - PluginResult* result = [PluginResult - resultWithStatus: PGCommandStatus_OK + CDVPluginResult* result = [CDVPluginResult + resultWithStatus: CDVCommandStatus_OK messageAsDictionary: resultDict ]; @@ -166,8 +163,8 @@ - (void)returnSuccess:(NSString*)scannedText format:(NSString*)format cancelled: //-------------------------------------------------------------------------- - (void)returnError:(NSString*)message callback:(NSString*)callback { - PluginResult* result = [PluginResult - resultWithStatus: PGCommandStatus_OK + CDVPluginResult* result = [CDVPluginResult + resultWithStatus: CDVCommandStatus_OK messageAsString: message ]; From ff704680496af66fc907976057ad7f859ddeecd4 Mon Sep 17 00:00:00 2001 From: Philip Majewski Date: Wed, 22 May 2013 14:57:44 +0200 Subject: [PATCH 2/3] Changed JS Example, credits --- iPhone/BarcodeScanner/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iPhone/BarcodeScanner/README.md b/iPhone/BarcodeScanner/README.md index 7c851a9e..33cf8c79 100644 --- a/iPhone/BarcodeScanner/README.md +++ b/iPhone/BarcodeScanner/README.md @@ -4,6 +4,8 @@ Originally by Matt Kane Modifications by IBM +Ported to cordova 2.7 by pille72 + ## Using the plugin ## The plugin requires the AVFoundation Framework, which is only available under @@ -35,17 +37,18 @@ The `scan` function is invoked as follows: A full example could be: - window.plugins.barcodeScanner.scan( + var myScanner = new PGBarcodeScanner(); + myScanner.scan( function(result) { if (result.cancelled) alert("the user cancelled the scan") else - alert("we got a barcode: " + result.text) + document.write(result.text); }, function(error) { alert("scanning failed: " + error) } - ) + ); ## `encode()` method ## @@ -99,7 +102,7 @@ at the bare minumum a transparent view that is connected to the PGbcsViewControl * In the `Supporting Files` directory of your project, add a new plugin by editing the file `PhoneGap.plist` and in the `Plugins` dictionary adding the following key/value pair: - * key: `com.phonegap.barcodeScanner` + * key: `PGBarcodeScanner` * value: `PGBarcodeScanner` * Add the following libraries to your Xcode project, if not already there: * AVFoundation.framework From 19a5f753fe06db67740ff69ff76e45ffdd0be27d Mon Sep 17 00:00:00 2001 From: Philip Majewski Date: Wed, 22 May 2013 14:58:20 +0200 Subject: [PATCH 3/3] Changed to current Cordova API --- iPhone/BarcodeScanner/barcodescanner.js | 34 ++++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/iPhone/BarcodeScanner/barcodescanner.js b/iPhone/BarcodeScanner/barcodescanner.js index d193f459..7a88bcd4 100644 --- a/iPhone/BarcodeScanner/barcodescanner.js +++ b/iPhone/BarcodeScanner/barcodescanner.js @@ -5,19 +5,18 @@ * Copyright (c) Matt Kane 2010 * Copyright (c) 2010, IBM Corporation */ +var PGBarcodeScanner; ;(function(){ - -if (PhoneGap.hasResource("barcodeScanner")) return - -PhoneGap.addResource("barcodeScanner") +if (!window.Cordova) window.Cordova = window.cordova; +//PhoneGap.addResource("PGBarcodeScanner") //------------------------------------------------------------------- -var BarcodeScanner = function() { +PGBarcodeScanner = function() { } //------------------------------------------------------------------- -BarcodeScanner.Encode = { +PGBarcodeScanner.Encode = { TEXT_TYPE: "TEXT_TYPE", EMAIL_TYPE: "EMAIL_TYPE", PHONE_TYPE: "PHONE_TYPE", @@ -27,7 +26,7 @@ BarcodeScanner.Encode = { } //------------------------------------------------------------------- -BarcodeScanner.prototype.scan = function(success, fail, options) { +PGBarcodeScanner.prototype.scan = function(success, fail, options) { function successWrapper(result) { result.cancelled = (result.cancelled == 1) success.call(null, result) @@ -36,7 +35,7 @@ BarcodeScanner.prototype.scan = function(success, fail, options) { if (!fail) { fail = function() {}} if (typeof fail != "function") { - console.log("BarcodeScanner.scan failure: failure parameter not a function") + console.log("PGBarcodeScanner.scan failure: failure parameter not a function") return } @@ -48,15 +47,15 @@ BarcodeScanner.prototype.scan = function(success, fail, options) { if ( null == options ) options = [] - return PhoneGap.exec(successWrapper, fail, "com.phonegap.barcodeScanner", "scan", options) + cordova.exec(successWrapper, fail, "PGBarcodeScanner", "scan", options); } //------------------------------------------------------------------- -BarcodeScanner.prototype.encode = function(type, data, success, fail, options) { +PGBarcodeScanner.prototype.encode = function(type, data, success, fail, options) { if (!fail) { fail = function() {}} if (typeof fail != "function") { - console.log("BarcodeScanner.scan failure: failure parameter not a function") + console.log("PGBarcodeScanner.scan failure: failure parameter not a function") return } @@ -65,19 +64,18 @@ BarcodeScanner.prototype.encode = function(type, data, success, fail, options) { return } - return PhoneGap.exec(success, fail, "com.phonegap.barcodeScanner", "encode", [{type: type, data: data, options: options}]) + cordova.exec(success, fail, "PGBarcodeScanner", "encode", [{type: type, data: data, options: options}]); } //------------------------------------------------------------------- -PhoneGap.addConstructor(function() { +/*PhoneGap.addConstructor(function() { if (!window.plugins) window.plugins = {} - if (!window.plugins.barcodeScanner) { - window.plugins.barcodeScanner = new BarcodeScanner() + if (!window.plugins.PGBarcodeScanner) { + window.plugins.PGBarcodeScanner = new PGBarcodeScanner() } else { - console.log("Not installing barcodeScanner: window.plugins.barcodeScanner already exists") + console.log("Not installing PGBarcodeScanner: window.plugins.PGBarcodeScanner already exists") } -}) - +})*/ })(); \ No newline at end of file