iPhone QR Barcode Reader !

2,095 views
Skip to first unread message

Nn

unread,
Mar 26, 2012, 8:29:00 AM3/26/12
to phonegap
Hi,

I have implemented the phonegap plugin for iphone of the barcode
scanner, using only their javascript, and its working perfectly on my
iphone device, i push scan button, cam opens with square canvas, scans
barcode quite fast, then returns a text line with the content of the
barcode like a url or text and many other attributes like this:
Scanned: success: {"format":"QR_CODE","cancelled":false,"text":"http://
www.google.com"}

My question is, from there how do i let my app if its a url to
retrieve only that link and open it automatically in safari, if its a
text to open it in notes etc...?

Thx in advance,

Nn

unread,
Mar 29, 2012, 2:43:54 PM3/29/12
to phonegap
Hi,

My post about this was deleted the next day for some reason, so here
it is:

I am new to this, i have already an app on appstore developed on
phonegap, i want now to integrate zxing QR reader into it. i did all
the necessary steps in xcode, and modified my index.html file with the
javascript, it works perfectly, and the camera scans the QR code, and
returns to the previous page with the result:

{"format":"QR_CODE","cancelled":false,"text":"http://www.google.com"}

Now i am Not an advanced programmer, so i want to parse the above
result, remove all except the last part which contains the actual
content of a QR code (so i only need whats in the "text" key), and
then i want to make it so that if its a URL it
opens directly in safari that link after scan, or if its an SMS opens
a new msg with the content immediately etc...

any response would be great even if just to handle the output text
above to remove parts of it.

Thx in advance,

Nn

unread,
Apr 10, 2012, 3:52:17 PM4/10/12
to phonegap
nobody successfully used zxing barcode scanner with phonegap ?

Libby

unread,
Apr 10, 2012, 4:40:57 PM4/10/12
to phon...@googlegroups.com
Part 2 of my barcode scanner tutorial
gives some ideas and code for handling successful
scan : see here. Tutorial discusses, or code attached
to page.

Tutorials are for AppLaud (PhoneGap / Android), but
it's all javascript!  Part 1 of the tutorial here.

HTH,
Libby

Nn

unread,
Apr 12, 2012, 7:08:32 AM4/12/12
to phonegap
Hi Libby,

Thanks a lot for your help,

I have imported the tmt3p2.js file into the main html file with
everything else, and in there i call the:
function clickScan() {
window.plugins.barcodeScanner.scan(
scanSuccess,
function(error) {
alert("Scan failed: " + error);
});
};

now when i test it on my device, the camera opens and it catches the
qr code and goes back to the html page but with no result and no
alert,
if i am inside the camera and i push cancel button instead of
scanning, it does return an alert saying scan format undefine, scan
value: Not supported. which means that it is going through ur tmt3
functions but only goes into the last else, if i scan successfully i
have placed alerts inside the first if else, they r not showing so its
not going in them on successful scan. what do u think is the problem ?

lemme know if u need my full html and JS code.

Thx a lot,

Patrick Mueller

unread,
Apr 12, 2012, 7:39:23 AM4/12/12
to phon...@googlegroups.com
On 4/12/12 7:08 AM, Nn wrote:
> I have imported the tmt3p2.js file into the main html file with
> everything else, and in there i call the:
> function clickScan() {
> window.plugins.barcodeScanner.scan(
> scanSuccess,
> function(error) {
> alert("Scan failed: " + error);
> });
> };
>
> now when i test it on my device, ...

In case folks didn't realize, there are two different versions of the
iOS BarcodeScanner in the github repo:

iOS:
https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

iPhone:
https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/BarcodeScanner

The names "iOS" and "iPhone" are ... a little vague. My understanding
is that the "iOS" version is for >= Cordova 1.5, and that the "iPhone"
version is for <= Cordova 1.5 (including PhoneGap 1.x).

Make sure you're using the appropriate one.

And then read the appropriate README.md (embedded in the pages linked to
above), and make sure you're following all the instructions.

Nn

unread,
Apr 12, 2012, 7:53:16 AM4/12/12
to phonegap
thx for the reply patrick,

i am using cordova 1.5 so both versions should work here.

and used libby's javascript tutorial for success handling.

Have u tried this scanner on iphone ?


On Apr 12, 1:39 pm, Patrick Mueller <pmue...@muellerware.org> wrote:
> On 4/12/12 7:08 AM, Nn wrote:
>
> > I have imported the tmt3p2.js file into the main html file with
> > everything else, and in there i call the:
> > function clickScan() {
> > window.plugins.barcodeScanner.scan(
> >         scanSuccess,
> >         function(error) {
> >             alert("Scan failed: " + error);
> >         });
> > };
>
> > now when i test it on my device, ...
>
> In case folks didn't realize, there are two different versions of the
> iOS BarcodeScanner in the github repo:
>
> iOS:https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeS...
>
> iPhone:https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/Barco...

Patrick Mueller

unread,
Apr 13, 2012, 8:19:25 AM4/13/12
to phon...@googlegroups.com
On 4/12/12 7:53 AM, Nn wrote:
> i am using cordova 1.5 so both versions should work here.

Ah crap. Got that wrong.

correction:

My understanding is that the "iOS" version is for >= Cordova 1.5, and

that the "iPhone" version is for <= Cordova 1.4 (including PhoneGap 1.x).

So, the iPhone version will not work on 1.5. For Cordova >= 1.5, you
need to use the "iOS" version.

Pretty sure I tried the "iOS" version on 1.5, but haven't tried it on
1.6, and suspect it may not work there.

Gokhan

unread,
Apr 13, 2012, 8:30:37 AM4/13/12
to phon...@googlegroups.com
Hi, I run phonegap app in android using barcode plugin. But i'm new at xcode, can you help me about how to add plugin ios, I tryed to add, but when i run app, it closed. thanks. 

26 Mart 2012 Pazartesi 15:29:00 UTC+3 tarihinde Nn yazdı:

Nn

unread,
Apr 13, 2012, 10:13:12 AM4/13/12
to phonegap
Hi Patrick,

yes i am using iOS, and as i mentioned earlier, if i try the example
as is, the plugin works perfectly, the cam with the frame opens and it
scans the barcode and returns to the thml page with the text inside of
the barcode.

it only stops giving the output text when i use libby's android
javascript to handle success scans.

On Apr 13, 2:19 pm, Patrick Mueller <pmue...@muellerware.org> wrote:
> On 4/12/12 7:53 AM, Nn wrote:
>
> > i am using cordova 1.5 so both versions should work here.
>
> Ah crap.  Got that wrong.
>
> correction:
>
> My understanding is that the "iOS" version is for >= Cordova 1.5, and
> that the "iPhone" version is for <= Cordova 1.4 (including PhoneGap 1.x).
>
> So, theiPhoneversion will not work on 1.5.  For Cordova >= 1.5, you

Nn

unread,
Apr 14, 2012, 10:05:47 AM4/14/12
to phonegap
Just wanna say i modified and cropped a little of your script and now
its working perfectly.

You're a genius.

Thx,

On Apr 10, 10:40 pm, Libby <libby.bald...@gmail.com> wrote:
> Part 2 of my barcode scanner tutorial
> gives some ideas and code for handling successful
> scan : see here<http://www.mobiledevelopersolutions.com/home/start/twominutetutorials...>. Tutorial
> discusses, or code attached
> to page.
>
> Tutorials are for AppLaud (PhoneGap / Android), but
> it's all javascript!  Part 1 of the tutorial here<http://www.mobiledevelopersolutions.com/home/start/twominutetutorials...>
> .

Jeicko

unread,
Apr 15, 2012, 4:20:13 AM4/15/12
to phon...@googlegroups.com
Hi,

My config is : XCode 4.3.2, Cordova 1.6, "iOS" version in github.

I have import all libraries.
I have add plugin : key "BarcodeScanner" value "CDVBarcodeScanner"
My html has cordova-1.6.0.js et barcodescanner.js

When I try on my phone or simulator "window.plugins.barcodeScanner" return "undefined" all the time on "clickScan()" function.
I have 0 error in Output console.

Have you an idea ?

################################

        function clickScan() {

            navigator.notification.alert("VAR:"+window.plugins.barcodeScanner);

            window.plugins.barcodeScanner.scan(scannerSuccess, scannerFailure);

        }

################################

HarryFu

unread,
Apr 15, 2012, 1:43:05 PM4/15/12
to phon...@googlegroups.com
Having the same problem here, have tried cordova 1.5 and 1.6 running barcodeScanner-plugin from iOS plugins-folder and getting an "undefined" value by testing "window.plugins.barcodeScanner" with an alert command. I could not finde the cordova.hasResource and cordova.addResource functions that are called in barcodescanner.js in the cordova.js file. Looks like they are deprecated (CB-298). Can this be the problem?

If anyone has a running version with phonegap 1.4.1, 1.5 or 1.6 it would be nice if he can help me by getting this running.

Thanks

Nn

unread,
Apr 17, 2012, 6:15:32 AM4/17/12
to phonegap
Disregard the full tmt3p2.js file, just copy one part of it into ur
barcode html page and make it look like this:

under:
function clickScan() {
window.plugins.barcodeScanner.scan(scannerSuccess,scannerFailure);
}

Put this:

function scannerSuccess(result) {

console.log("scannerSuccess: result: " + result)

var scanVal = result.text;
if (scanVal.indexOf("http") === 0) {
navigator.notification.confirm(
'Open in browser ?',
function (b) {
if (b === 1) {

window.plugins.childBrowser.showWebPage(scanVal);
}
},
result.text,
'Open, Cancel'
);
} else {
navigator.notification.alert(
result.text,
function (){},
'Scan Value:',
'Done'
);
}
}


@jeiko, if u wanna test it with your alert use:

alert(result.text);

inside the scannerSuccess function.



On Apr 15, 7:43 pm, HarryFu <harr...@t-online.de> wrote:
> Having the same problem here, have tried cordova 1.5 and 1.6 running
> barcodeScanner-plugin from iOS plugins-folder and getting an "undefined"
> value by testing "window.plugins.barcodeScanner" with an alert command. I
> could not finde the cordova.hasResource and cordova.addResource functions
> that are called in barcodescanner.js in the cordova.js file. Looks like
> they are deprecated (CB-298 <https://issues.apache.org/jira/browse/CB-298>).

drawer

unread,
Apr 24, 2012, 6:32:53 AM4/24/12
to phonegap
As a newbie, I am on my way trying to integrate zxing QR reader into
iPhone App.
I am using Xcode 4.3.2 and iOS SDK 5.1

I tried following all steps in this link and adding the plugins
successfully, but after I press the run button, it gives a bunch of
errors.
https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

I also tried to run the example provided and test it on my iPhone...
After opening the test app, and pressed the "scan something" button,
camera not open, and there's no response at all.

Is there a more detailed tutorial online (on using PhoneGap project
template to integrate QR reader) that I can follow?

Thx in advance.

drawer

unread,
Apr 24, 2012, 6:32:26 AM4/24/12
to phonegap
As a newbie, I am on my way trying to integrate zxing QR reader into
iPhone App.
I am using Xcode 4.3.2 and iOS SDK 5.1

I tried following all steps in this link and adding the plugins
successfully, but after I press the run button, it gives a bunch of
errors.
https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

I also tried to run the example provided and test it on my iPhone...
After opening the test app, and pressed the "scan something" button,
camera not open, and there's no response at all.

Is there a more detailed tutorial online (on using PhoneGap project
template to integrate QR reader) that I can follow?

Thx in advance.




On Apr 17, 6:15 pm, Nn <zeus.its...@gmail.com> wrote:

alan blount

unread,
May 28, 2013, 12:00:30 PM5/28/13
to phon...@googlegroups.com
in case this helps anyone:
https://github.com/zeroasterisk/PhoneGap-BarcodeScanner-Example-iOS

On Thursday, August 23, 2012 1:28:41 AM UTC-4, Praveen Kh wrote:
Hi,

Could any one give me a working copy of JS files for iOS Barcode scanner [iPad]. I tried all different combination of JS files but still its giving some error like Object #<Object> has no method 'exec' :(

Thanks,
Praveen KH


On Thursday, June 14, 2012 11:35:27 PM UTC+5:30, Son Pham wrote:
Hi Nn

Could you help me to run BarCodeScanner PhoneGap on Devices ? I run it but when I click to Scan, nothing to display.... :-s I tried to fix but nothing to show.
I followed tutorial at: 

but not successful :( 

Thank & Best Regards,
Kevin
Reply all
Reply to author
Forward
0 new messages