Search documentation of mob

# Mob.Scanner (mob v0.6.18)

Copy Markdown View Source

QR code and barcode scanner.

Requires `:camera` permission (request via `Mob.Permissions.request/2`).

Opens a full-screen camera preview. When a code is detected the view dismisses automatically and the result is delivered to `handle_info`:

    handle_info({:scan, :result,    %{type: :qr, value: "https://..."}}, socket)
    handle_info({:scan, :cancelled},                                       socket)

iOS: `AVCaptureMetadataOutput`. Android: `CameraX` + ML Kit `BarcodeScanning`.

> Android dependency: add to `app/build.gradle`: `implementation 'com.google.mlkit:barcode-scanning:17.2.0'` `implementation 'androidx.camera:camera-camera2:1.3.0'` `implementation 'androidx.camera:camera-lifecycle:1.3.0'` `implementation 'androidx.camera:camera-view:1.3.0'`

## Summary

### Types

format()

### Functions

scan(socket, opts \\ [])

Open the barcode scanner.

## Types

# format()

    @type format() ::
      :qr
      | :ean13
      | :ean8
      | :code128
      | :code39
      | :upca
      | :upce
      | :pdf417
      | :aztec
      | :data_matrix

## Functions

# scan(socket, opts \\ [])

    @spec scan(
      Mob.Socket.t(),
      keyword()
    ) :: Mob.Socket.t()

Open the barcode scanner.

Options:

- `formats: [format]` — list of barcode formats to detect (default `[:qr]`)