MLKitBarcodeScanning 架構參考資料

BarcodeScanner

class BarcodeScanner : NSObject

掃描圖片中條碼的條碼掃描器。

  • 傳回具有指定選項的條碼掃描器。

    聲明

    Swift

    class func barcodeScanner(options: MLKBarcodeScannerOptions) -> Self

    參數

    options

    包含條碼掃描器設定的選項。

    傳回值

    以指定選項設定的條碼掃描器。

  • 傳回含預設選項的條碼掃描器。

    聲明

    Swift

    class func barcodeScanner() -> Self

    傳回值

    採用預設選項設定的條碼掃描器。

  • 無法使用,使用類別方法。

  • 處理指定圖片進行條碼掃描。

    聲明

    Swift

    func process(_ image: MLKitCompatibleImage) async throws -> [MLKBarcode]

    參數

    image

    要處理的圖片。

    completion

    用於在主要佇列上傳回條碼或發生錯誤的處理常式。

  • 傳回指定圖片中的條碼結果;如果發生錯誤,則傳回 nil。條碼掃描會在呼叫執行緒上同步。

    建議您從主執行緒呼叫此方法,以免封鎖 UI。因此,如果在主執行緒上呼叫此方法,就會引發 NSException

    聲明

    Swift

    func results(in image: MLKitCompatibleImage) throws -> [MLKBarcode]

    參數

    image

    要用於取得結果的圖片。

    error

    取得結果時發生錯誤時填入的選用錯誤參數。

    傳回值

    條碼陣列會產生指定的圖片,如果發生錯誤,則會產生 nil