Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS BarcodeScanner ported to cordova 2.7 #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions iPhone/BarcodeScanner/PGBarcodeScanner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
//------------------------------------------------------------------------------
#import "zxing-all-in-one.h"

#ifdef PHONEGAP_FRAMEWORK
#import <PhoneGap/PGPlugin.h>
#else
#import "PGPlugin.h"
#endif
#import <CORDOVA/CDVPlugin.h>


//------------------------------------------------------------------------------
// Adds a shutter button to the UI, and changes the scan from continuous to
Expand All @@ -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;
Expand Down Expand Up @@ -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
];

Expand All @@ -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
];

Expand All @@ -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
];

Expand Down
11 changes: 7 additions & 4 deletions iPhone/BarcodeScanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ##

Expand Down Expand Up @@ -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
Expand Down
34 changes: 16 additions & 18 deletions iPhone/BarcodeScanner/barcodescanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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")
}
})

})*/
})();