---
name: "scanCode"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
platform:
  - "iOS"
  - "Android"
async: true
---

## scanCode

> [VERSION] BaseKit >= 2.3.2

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Invoke the client scan UI to scan. Note: On Android, only the result field in the returned data is usable; other fields are not meaningful.

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `onlyFromCamera` | `boolean` | No | `false` | `2.3.2` | Whether to scan only via camera, disallow selecting images from the gallery |
| `isShowActionTitle` | `boolean` | No | `true` | `3.3.3` | Whether to show the action title (Android only) |
| `isShowTorch` | `boolean` | No | `false` | `3.3.3` | Whether to show the flashlight (Android only) |
| `isShowKeyboard` | `boolean` | No | `false` | `3.12.0` | Whether to show the input for setup code |
| `keyboardBean` | `KeyboardBean` | No | - | `3.12.0` | Custom text for the setup code input |
| `customTips` | `string` | No | - | `3.3.3` | Custom prompt text (Android only) |
| `scanType` | `string[]` | No | `["barCode", "qrCode"]` | `2.3.2` | Scan type |
| `complete` | `() => void` | No | - | - | Completion callback (executes on success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback for API call success |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Callback for API call failure |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `result` | `string` | `3.2.6` | Scanned content |
| `scanType` | `string` | `3.2.6` | Type of the scanned code |
| `charSet` | `string` | `3.2.6` | Character set of the scanned code |
| `path` | `string` | `3.2.6` | When the scanned code is the current miniapp QR code, this field is returned with the path carried by the QR code (may be absent) |
| `rawData` | `string` | `3.2.6` | Raw data, base64-encoded |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Extended error code |
| `errorMsg` | `string` | Extended error info |


### Referenced Types

##### `interface` KeyboardBean

| Property | Type | Required | Since | Description |
| --- | --- | --- | --- | --- |
| `title` | `string` | No | `3.12.0` | Keyboard title && input page title |
| `placeholder` | `string` | No | `3.12.0` | Input page placeholder text |
| `desc` | `string` | No | `3.12.0` | Input page description |
| `actionText` | `string` | No | `3.12.0` | Action button label on the input page |


### Examples

```tsx
// Open the client scan UI; callback returns the content and type after scanning (on Android, only the result field is valid)
ty.scanCode({
  onlyFromCamera: false,
  isShowActionTitle: true,
  isShowTorch: false,
  isShowKeyboard: false,
  scanType: ["barCode", "qrCode"],
  success: data => console.log("Scan result:", data.result, data.scanType),
  fail: error => console.error(error),
});
```
