AI-generated Key Takeaways
-
BarcodeScanneris a class used for scanning barcodes within images. -
It provides methods to create a scanner instance with custom or default options.
-
The
process(_:)method asynchronously scans an image for barcodes and returns the results. -
The
results(in:)method synchronously scans an image, but it should be called off the main thread to avoid blocking the UI.
BarcodeScanner
class BarcodeScanner : NSObjectA barcode scanner that scans barcodes in an image.
-
Returns a barcode scanner with the given options.
Declaration
Swift
class func barcodeScanner(options: MLKBarcodeScannerOptions) -> SelfParameters
optionsOptions containing barcode scanner configuration.
Return Value
A barcode scanner configured with the given options.
-
Returns a barcode scanner with the default options.
Declaration
Swift
class func barcodeScanner() -> SelfReturn Value
A barcode scanner configured with the default options.
-
Unavailable. Use the class methods.
-
Processes the given image for barcode scanning.
Declaration
Swift
func process(_ image: MLKitCompatibleImage) async throws -> [MLKBarcode]Parameters
imageThe image to process.
completionHandler to call back on the main queue with barcodes scanned or error.
-
Returns barcode results in the given image or
nilif there was an error. The barcode scanning is performed synchronously on the calling thread.It is advised to call this method off the main thread to avoid blocking the UI. As a result, an
NSExceptionis raised if this method is called on the main thread.Declaration
Swift
func results(in image: MLKitCompatibleImage) throws -> [MLKBarcode]Parameters
imageThe image to get results in.
errorAn optional error parameter populated when there is an error getting results.
Return Value
Array of barcode results in the given image or
nilif there was an error.