FUIBarcodeScanViewController
@available(visionOS, unavailable)
@MainActor
public class FUIBarcodeScanViewController : UIViewController, FUIBarcodeScannerDelegate
This UIViewController is to be used for user to scan for 1D and 2D codes using the device’s camera.
Developer may use segue in their storyboard to access this FUIBarcodeScanViewController in FUIBarcodeScanViewController.storyboard.
The delegate property of the FUIBarcodeScanViewController and the properties of the FUIBarcodeScanner may be set in the prepare for
segue function as follows:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destination = segue.destination as! UINavigationController
let vc = destination.viewControllers[0]
if vc is FUIBarcodeScanViewController {
let scanViewController = vc as! FUIBarcodeScanViewController
switch segue.identifier! {
case "CustomScanSegue":
scanViewController.barcodeScanner.scanMode = .qr
scanViewController.barcodeScanner.indicatorBorderColor = UIColor.red.cgColor
scanViewController.barcodeScanner.indicatorBorderWidth = 20
scanViewController.barcodeScanner.promptMessage = "Scan A QR Code"
scanViewController.barcodeScanner.scanResultTransformer = { s in
return s + "-transformed"
}
scanViewController.delegate = self
default:
break
}
}
}
Or, developer may use codes to instantiate this controller as follows:
func customScanFromCode(_ sender: Any) {
let scanViewController = FUIBarcodeScanViewController.createInstanceFromStoryboard()
scanViewController.barcodeScanner.scanMode = .qr
scanViewController.barcodeScanner.indicatorBorderColor = UIColor.red.cgColor
scanViewController.barcodeScanner.indicatorBorderWidth = 20
scanViewController.barcodeScanner.promptMessage = "Scan A QR Code"
scanViewController.barcodeScanner.scanResultTransformer = { s in
return "transformed"
}
scanViewController.delegate = self
let navController = UINavigationController(rootViewController: scanViewController)
self.navigationController?.present(navController, animated: true, completion: nil)
}
Also, developer needs to implement the FUIBarcodeScanViewControllerDelegate protocol
to be notified with a scan result:
func barcodeScanViewController(_ barcodeScanViewController: FUIBarcodeScanViewController, didReceiveScanResult scanResult: FUIBarcodeScanResult?) {
print("scan result: \(String(describing: scanResult?.scanResultString))")
if scanResult?.scanResultString != "success" {
alertInvalidQRCode()
} else {
barcodeScanViewController.dismiss(animated: true, completion: nil)
}
}
Attention
The delegate object with type FUIBarcodeScanViewControllerDelegate is declared as a weak reference. So on deallocation it will be automatically set to nil. To keep it alive as expected, developer should retain the delegate object during the whole execution scope.
-
The width of the scan guides image for regular sized devices in pixels.
The default is 640 px.
Declaration
Swift
@MainActor public var scanGuidesRegularWidth: CGFloat { get set } -
The height of the scan guides image for regular sized devices in pixels.
The default is 361 px.
Declaration
Swift
@MainActor public var scanGuidesRegularHeight: CGFloat { get set } -
The width of the scan guides image for compact sized devices in pixels.
The default is 343 px.
Declaration
Swift
@MainActor public var scanGuidesCompactWidth: CGFloat { get set } -
The height of the scan guides image for compact sized devices in pixels.
The default is 194 px.
Declaration
Swift
@MainActor public var scanGuidesCompactHeight: CGFloat { get set } -
This property indicates whether the effective scan area falls within the scan guide area.
The default value is
false, which means that the entire camera view area will be scanned.Declaration
Swift
@MainActor public var scansGuidesAreaOnly: Bool { get set } -
The close button which is on the left of the navigation bar.
Declaration
Swift
@IBOutlet @MainActor public private(set) weak var closeButton: UIBarButtonItem! { get } -
The
FUIBarcodeScannerin this view controller.Declaration
Swift
@MainActor public var barcodeScanner: FUIBarcodeScanner! { get set } -
The delegate for this
FUIBarcodeScanViewController.Declaration
Swift
@MainActor public weak var delegate: FUIBarcodeScanViewControllerDelegate? -
The effective
UINavigationController.Developer could set this to the
UINavigationControllerfor this view controller. If developer did not set this value, theUINavigationControllerof this view controller will be returned if it is not nil. Otherwise, the rootUINavigationControllerfrom thekeyWindow, if any, will be returned.Declaration
Swift
@MainActor public var effectiveNavigationController: UINavigationController? { get set } -
A code block that whill be invoked when the barcode scan view is closed.
Declaration
Swift
@MainActor public var onCloseBarcodeScanView: (() -> Void)? -
This property indicates if the scanner session is to automatically restart after a barcode has been discovered.
If this property is
true, the scanner session is restarted after the delegate’sdidReceiveScanResultfunction is invoked. Otherwise, the delegate implementation is responsible to restart the scanner session if desired.The default is true.
Declaration
Swift
@MainActor public var isAutoRestart: Bool -
A custom view to be displayed when a scan result is validated by the delegate.
The default is
nil. The developer needs to provide this custom view when appropriate.When this property is not
nil, the delegate’s functionfunc barcodeScanViewController(_ barcodeScanViewController: FUIBarcodeScanViewController, didReceiveScanResult scanResult: FUIBarcodeScanResult?, confirmationView: UIView) -> Boolwill be invoked and the
confirmationViewwill be displayed when the function returnstrue.Declaration
Swift
@MainActor public var confirmationView: UIView? -
Creates a
FUIBarcodeScanViewControllerobject from storyboard.Declaration
Swift
@MainActor public class func createInstanceFromStoryboard() -> FUIBarcodeScanViewControllerReturn Value
The instantiated
FUIBarcodeScanViewControllerobject. -
The scanner is stopped after it received a scan result. Call this function to start another scan.
Declaration
Swift
@MainActor public func restartScan()