![]() Otherwise, we reset the size of qrCodeFrameView to zero and set messageLabel to its default message. The very first thing we need to do is make sure that this array is not nil, and it contains at least one object. metadataObjects) of the method is an array object, which contains all the metadata objects that have been read. Insert the code below in the do-catch block: The preview layer is added as a sublayer of the current view. You use this preview layer in conjunction with an AV capture session to display video. This can be done using an AVCaptureVideoPreviewLayer, which actually is a CALayer. Now that we have set and configured an AVCaptureMetadataOutput object, we need to display the video captured by the device's camera on screen. The metadataObjectTypes property is also quite important as this is the point where we tell the app what kind of metadata we are interested in. So, we use DispatchQueue.main to get the default serial queue. According to Apple’s documentation, the queue must be a serial queue. A dispatch queue can be either serial or concurrent. In the above code, we specify the dispatch queue on which to execute the delegate’s methods. When new metadata objects are captured, they are forwarded to the delegate object for further processing. For now, continue to add the following lines of code in the do block of the viewDidLoad method: This class, in combination with the AVCaptureMetadataOutputObjectsDelegate protocol, is used to intercept any metadata found in the input device (the QR code captured by the device's camera) and translate it to a human-readable format.ĭon’t worry if something sounds weird or if you don’t totally understand it right now - everything will become clear in a while. The AVCaptureMetaDataOutput class is the core part of QR code reading. In this case, the output of the session is set to an AVCaptureMetaDataOutput object. The AVCaptureSession object is used to coordinate the flow of data from the video input device to our output. To perform a real-time capture, we use the AVCaptureSession object and add the input of the video capture device. In the code above, we specify to retrieve the device that supports the media type. an URL) is displayed right at the bottom of the screen.Īssuming you’ve read the previous chapter, you should know that the AVCaptureDevice.DiscoverySession class is designed to find all available capture devices matching a specific device type. When the app is launched, it takes advantage of the iPhone's rear camera to spot the QR code and recognizes it automatically. The app works pretty much like a video capturing app but without the recording feature. Keep this point in mind, as it'll help you understand the entire chapter. That's why the barcode scanning feature is added in the AVFoundation framework. Before we proceed to build the demo app, however, it's important to understand that any barcode scanning in iOS, including QR code scanning, is totally based on video capture. The demo app that we're going to build is fairly simple and straightforward. Simply go to Creating a QR Code Reader App Quick tip: You can generate your own QR code. Now, you can use the built-in AVFoundation framework to discover and read barcodes in real-time.Ĭreating an app for scanning and translating QR codes has never been so easy. ![]() Prior to iOS 7, you had to rely on third-party libraries to implement the scanning feature. As an iOS developer, you may wonder how you can empower your app to read a QR code. They appear in magazines, newspapers, advertisements, billboards, name cards and even food menu. In some countries, QR codes can be found nearly everywhere. With the rising prevalence of iPhone and Android phones, the use of QR codes has been increased dramatically. If you’re interested in learning more, you can check out the official website of QR code. ![]() I don’t want to go into the technical details of the QR code here. Thus this contributes to its capability of storing a larger amount of data in both numeric and letter form. Unlike the basic barcode that you’re familiar with, a QR code contains information in both the horizontal and vertical direction. Originally designed for tracking parts in manufacturing, QR code has gained popularity in consumer space in recent years as a way to encode the URL of a landing page or marketing information. QR (short for Quick Response) code is a kind of two-dimensional bar code developed by Denso. In case you haven’t heard of it, just take a look at the above image - that’s a QR code. So, what’s QR code? I believe most of you know what a QR code is. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |