Huawei ScanKit iOS Example written in Swift
HUAWEI Scan Kit scans and parses all major 1D and 2D barcodes and generates QR codes, helping you quickly build barcode scanning functions into your apps.
ScanKit works in suboptimal situations, such as under dim lighting or when the barcode is reflective, dirty, blurry, or printed on a cylindrical surface. Scan Kit allows support for 13 major barcode formats:
- 1D barcodes: EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code 39, Code 93, Code 128, and ITF
- 2D barcodes: QR code, Data Matrix, PDF417, and Aztec
In this reading, we are going to cover how to integrate and use ScanKit.
Integration Using Pods
As an example I am going to show you how to add it with using CocoaPods.
Create a Podfile (If you don’t have).
$ cd your-project-directory
$ pod init
Edit the Podfile to add pod dependencies:
Finally, run the code below:
When you run
pod install code, another file with .xcworkspace extension will be created. Open your project with using .xcworkspace file.
And we also need to add a camera and library usage permission. To do this add following code into your Info.plist file.
Scan Kit can be called in three ways, from which you can choose as needed. These are Default View, Customized View and Bitmap. If you want to use barcode scanning capabilities quickly, Default View or Customized View can be used. If you want to customize the scanning process and control the camera by yourself, you have to use Bitmap.
Let’s see how can we use Default View first. Import ScanKitFrameWork into your class.
We are going to Create a HmsScanOptions and use it to create HmsDefaultScanViewController as you see in the code below:
We created a HmsDefaultScanViewController and assigned delegate as self and added hmsDefaultScanViewController’s view to self.view
In the end, we are going to add DefaultScanDelegate into our class and use its methods. We can declare the delegate at the end of the class as an extension.
You can parse result dictionary with the code below:
After scanning barcode or QR code one of delegate methods will be called and you can parse the scanned text.
For detailed scan types you can check my demo project in GitHub: