Scan with Zbar for QR code or barcode (one-dimensional code)

Source: Internet
Author: User

next, because using avfoundation has been unable to scan our QR code, and finally decided to use a barcode. I added the EAN13 barcode type (the type we used to generate the barcode) in Avcapturemetadataoutput's metadataobjecttypes, unfortunately, is still not recognized, but Baidu's other EAN13 types of barcodes can be identified, this issue is still unresolved.

Finally, I decided to try Zbar,bingo!. The efficiency is very high. The following describes the use of Zbar process.

First, use Cocopods to integrate Zbar in the project and then import ZBARSDK in the header file, because I need to customize the scan interface, so use Zbarreaderview as follows:


Where Scancrop is a property that sets a valid zone, which is equivalent to

avcapturemetadataoutput in rectofinterest (see my previous blog for specific information), other properties are no longer mentioned.

Here are some of the problems encountered during the use of Zbar:

1. When using avfoundation, it is necessary to use asynchronous threading to prevent the blocking of the mainline loads loading interface when configuring instance variables for each class. When using Zbarreaderview, if you do not use an asynchronous thread, there will be blocking, but if you are using an asynchronous thread, there is a problem: it takes a while to enter the sweep code interface to the lens, and this time increases as the number of times it enters the interface, I found that the problem was self in the _initwithimagescanner method of implementing file Zbarreaderviewimpl in Zbarreaderview. Device = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo ]; method, but the problem is still not solved (I am too food, and asked the great God can point twos), because the waiting time is unacceptable, I thought of another way: To add the scanning view of the method from Viewdidload to Viewdidappear, Then add a loading view in the Viewwillappear, so that clicking on the button of the page that goes into the scan view does not need to wait for it to appear loading until the load finishes showing the scan view. Due to business needs, after the scan is completed, go to the next page to operate, and then you can choose to go to the scan view again, so the viewdidappear will be executed more than once to load the scan view, in order to solve this problem, I use a global variable to ensure that the scan view is loaded only once. The specific code is as follows:


2. When using Zbar for scanning, the first entry to the page will appear jitter, the specific cause is unknown, not resolved.

Summary: At this point, scanning function can also be used, but due to limited personal capacity, business has repeatedly retreated, there are many problems. I would appreciate it if I could find a friend of this blog to help me out. The road is long its repair far ~ ~ ~

Scan with Zbar for QR code or barcode (one-dimensional code)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.