The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Monica_G (28) [Avatar] Offline
#1
Hi,

I'm having trouble getting the barcode reader to detect a barcode. I've installed the app on to my phone (SE iOS 11.4). The app launches and I'm able to bring up the "Detect barcode" scene. However, I am not able to detect a barcode. I've tried detecting a barcode in both portrait and landscape mode. I've tried different books. When I get the phone close to the barcode I'm not able to focus the camera, so the barcode is bleary and not detected. From further away the barcode is clear but is not detected. I am using the code from Chapter13.7.AVAudioPlayer

Is there a trick to get the phone to read the barcode?

Thanks!

Monica
Craig Grummitt (50) [Avatar] Offline
#2
barcode
[ 670 KB ]
Hi Monica,

That's a strange one!

1. The first thing to do is double-check is if there's a problem with the barcode itself. Attached is the barcode for the book itself which I don't have any problems with scanning.
2. Have you called the `startRunning` method of the captureSession?
3. Is the metadataOutput method being called? Perhaps print to console in the first line of that method to check.

Monica_G (28) [Avatar] Offline
#3
Hi Craig,

I figured it out. In the github repo (branch Chapter13.7.AVAudioPlayer) the metadataOutput function is:

func metadataOutput(captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {


But in the book it is (note the addition of the _):

func metadataOutput(_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {


The book code works! I point it at an ISBN and it captures the data and fills in the ISBN field.

Thanks!

Monica
68128 (1) [Avatar] Offline
#4
I had the same problem. Thank you Monica for the solution. It saved me a lot of time.

Bernd
Craig Grummitt (50) [Avatar] Offline
#5
Good detective skills Monica! You're right, the syntax of the metadataOutput method needed updating. I've updated this in the repos now. Glad this helped you too, 61218!