# Barcode Scanning / iOS

**URL:** <https://forum.xojo.com/t/barcode-scanning-ios/20776>\
**Category:** iOS\
**Created:** [December 9, 2014, 7:02pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776 "2014-12-09T19:02:03Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [December 24, 2014, 8:43pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/21 "2014-12-24T20:43:10Z")

</div>

[quote=154896:@Jason King]Here is an implementation using CoreImage. From what I was reading, it will only function on a physical device and my tests indicate the same since a CIDetector cannot be created in the simulator. If someone can test it and let me know if it works since I don’t yet have an iOS license that would be great.  
[https://www.dropbox.com/s/nnpb8gphiq2c7bk/QRReader.zip?dl=0](https://www.dropbox.com/s/nnpb8gphiq2c7bk/QRReader.zip?dl=0)

Edit: Link was wrong.[/quote]

It seems to work and says “Hello world”.

I simply had to modify the button Action to

```auto
Label1.Text = QRReader.Read(qr_code_without_logo)
```

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [December 24, 2014, 8:45pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/22 "2014-12-24T20:45:58Z")

</div>

Yeah that and the image not being found by the project was the problem with the original link.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [December 24, 2014, 8:46pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/23 "2014-12-24T20:46:30Z")

</div>

Thanks for testing! That’s exactly what was supposed to be displayed by that code.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [December 24, 2014, 8:52pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/24 "2014-12-24T20:52:53Z")

</div>

So now using the Camera class I posted above and the QRReader module you should be able read a QR code using the iPhone/iPad camera. Enjoy!

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [December 24, 2014, 8:56pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/25 "2014-12-24T20:56:27Z")

</div>

Great Christmas gift from Jason. 🙂  
Thank you again for helping us here !

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [December 24, 2014, 8:58pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/26 "2014-12-24T20:58:32Z")

</div>

Strange the iOSEmulator cannot use the camera from a MBP. 🙂 That would make debugging much easier. 🙂

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [December 24, 2014, 9:17pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/27 "2014-12-24T21:17:19Z")

</div>

> [@154908:@Christoph De Vocht](#):
>
> Strange the iOSEmulator cannot use the camera from a MBP. 🙂 That would make debugging much easier. 🙂

Yeah I agree, I expected it to use the iSight camera but it doesn’t. Maybe an oversight by Apple, or maybe there is something which prevents it from working. We will probably never know.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [December 24, 2014, 10:39pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/28 "2014-12-24T22:39:56Z")

</div>

I just combined the camera project and QR Reader from Jason King into one project I called QRCamera. It allows to take a picture of a QR code, then read the content of it.

That is the base for what the OP was asking 🙂

[QRCamera.xojo\_binary\_project](http://fontmenu.com/xojo/QRCamera.xojo_binary_project)

---

<div class="post-metadata">

**Author:** ![Valdemar\_De\_SOUSA](https://forum.xojo.com/user_avatar/forum.xojo.com/valdemar_de_sousa/32/21374_2.png) [@Valdemar\_De\_SOUSA](https://forum.xojo.com/u/Valdemar_De_SOUSA)\
**Post date:** [December 25, 2014, 12:02pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/29 "2014-12-25T12:02:07Z")

</div>

🙂 Thanks Michel and Jason

---

<div class="post-metadata">

**Author:** ![Chris\_O\_Brien](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_o_brien/32/452_2.png) [@Chris\_O\_Brien](https://forum.xojo.com/u/Chris_O_Brien)\
**Post date:** [January 4, 2015, 6:48pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/30 "2015-01-04T18:48:06Z")

</div>

Hi, The QRCode Reader works great, but I see from docs you can only use TypeQRCode or TypeRectangle. Would reading Code3of9 be completely different or even possible?

Thanks

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [January 4, 2015, 7:45pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/31 "2015-01-04T19:45:38Z")

</div>

Yes, reading Code 3of9 would be completely different and is currently not possible with declares. It would require the use of several AVFoundation classes which cannot be used in Xojo because Xojo uses a cooperative threading model and the callbacks from AVFoundation are invoked on unmanaged threads which leads to exceptions in Xojo. You would have to implement reading Code3of9 in code yourself ☹ Maybe using TypeRectangle will allow you to identify the barcode and you could then extract the image to process?

---

<div class="post-metadata">

**Author:** ![Chris\_O\_Brien](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_o_brien/32/452_2.png) [@Chris\_O\_Brien](https://forum.xojo.com/u/Chris_O_Brien)\
**Post date:** [January 4, 2015, 8:00pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/32 "2015-01-04T20:00:31Z")

</div>

Thanks very much Jason. Question answered 🙂

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 4, 2015, 8:53pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/33 "2015-01-04T20:53:24Z")

</div>

3of9 is not terribly complex : [http://www.barcodeisland.com/code39.phtml](http://www.barcodeisland.com/code39.phtml)

If you use the camera to get the picture of the barcode, then you can analyse it by fetching the black or white pixels from left to right. The start character will provide the synchronization data (the width or an elementary bar in pixels), then you can analyze the whole picture.

I would suggest starting with an impeccable representation such as what you can find at [images.google.com](http://images.google.com), and when your deciphering code is done, test with camera pictures. Since the camera pictures can be blurry or lack contrast, you will probably need to check the coherence of the extracted data.

I have never done it that way, but I designed bar code fonts, and code 39 is one of the simplest ones.

---

<div class="post-metadata">

**Author:** ![Chris\_O\_Brien](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_o_brien/32/452_2.png) [@Chris\_O\_Brien](https://forum.xojo.com/u/Chris_O_Brien)\
**Post date:** [January 4, 2015, 8:58pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/34 "2015-01-04T20:58:41Z")

</div>

Thanks very much Michel. I was doing some investigation on it after Jason’s reply - I knew it must be manageable since it’s possible to print 3 of 9 from a font. Your suggestions and links will help a lot.

Cheers

Chris

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 5, 2015, 8:21am UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/36 "2015-05-05T08:21:45Z")

</div>

Stupid spammer…

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [May 18, 2015, 4:28am UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/37 "2015-05-18T04:28:36Z")

</div>

@Chris O’Brien the new version of iOSKit (v1.2) has the classes necessary for reading Code 3 of 9 codes. There is a demo view which shows you how to use them. The values of metadataObjectTypes which can be used are all strings and you just have to specify the proper key(s) to read the barcodes:

`"org.gs1.UPC-E",
"org.iso.Code39",
"org.iso.Code39Mod43",
"org.gs1.EAN-13",
"org.gs1.EAN-8",
"com.intermec.Code93",
"org.iso.Code128",
"org.iso.PDF417",
"org.iso.QRCode",
"org.iso.Aztec"`  
If you have any questions please ask.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [May 18, 2015, 5:27am UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/38 "2015-05-18T05:27:20Z")

</div>

FWIW, we used Jason’s AVFoundation barcode scanning classes for scanning Passbook passes at XDC this year and they performed outstandingly.

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [July 20, 2015, 4:18pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/39 "2015-07-20T16:18:27Z")

</div>

[quote=152282:@Jason King]  
Demo project:  
[https://www.dropbox.com/s/ib3xswbydnjrm5c/Camera.xojo\_binary\_project?dl=0[/quote]](https://www.dropbox.com/s/ib3xswbydnjrm5c/Camera.xojo_binary_project?dl=0%5B/quote%5D)

Thanks for sharing.  
I was trying to modify your code to make the final code more like a single class you can drop in a view, to make it accessible from within whatever view it was dragged in.

The PresentInView method wants to have the view set passed though. Something I can’t really figure out yet.  
Any ideas?

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [July 20, 2015, 5:45pm UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/40 "2015-07-20T17:45:29Z")

</div>

Hi Edwin, that class has been updated in iOSKit. Please download the latest version there which also includes an example view of how to pass the view to the camera object.

[https://github.com/kingj5/iOSKit](https://github.com/kingj5/iOSKit)

Jason

---

<div class="post-metadata">

**Author:** ![Edwin\_van\_den\_Akker](https://forum.xojo.com/user_avatar/forum.xojo.com/edwin_van_den_akker/32/1063_2.png) [@Edwin\_van\_den\_Akker](https://forum.xojo.com/u/Edwin_van_den_Akker)\
**Post date:** [July 21, 2015, 8:03am UTC](https://forum.xojo.com/t/barcode-scanning-ios/20776/41 "2015-07-21T08:03:34Z")

</div>

> [@201528:@Jason King](#):
>
> Hi Edwin, that class has been updated in iOSKit.

Thanks Jason! I am trying to figure out how to drag the components in my project. I guess just slapping everything in a folder will be a neat solution?  
By the way: Is there a change that CoreLocation will be added? (to use GPS etc)

[Previous page](https://forum.xojo.com/t/barcode-scanning-ios/20776.md?page=1)

[Next page](https://forum.xojo.com/t/barcode-scanning-ios/20776.md?page=3)
