---
name: "share"
mode: "kit"
versionRequirements:
  - { name: "BizKit", version: "3.0.0" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
async: true
---

## share

> [VERSION] BizKit >= 3.0.0 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS

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

### Description

Share text, images, files, web pages, or mini program content via the specified channel

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `type` | `"WeChat" \| "Message" \| "Email" \| "More"` | No | `'WeChat'` | `3.0.0` | Share channel; defaults to WeChat if omitted. Options: WeChat, Message, Email, More |
| `title` | `string` | Yes | - | `3.0.0` | title Title |
| `message` | `string` | Yes | - | `3.0.0` | message Text content |
| `contentType` | `"text" \| "image" \| "file" \| "web" \| "miniProgram"` | No | `'text'` | `3.0.0` | contentType Content type |
| `recipients` | `string[]` | No | - | `3.0.0` | recipients Email/SMS recipients |
| `imagePath` | `string` | No | - | `3.0.0` | imagePath Image path |
| `filePath` | `string` | No | - | `3.0.0` | File share path, used when contentType == file; omitting it will cause the file share to fail |
| `webPageUrl` | `string` | No | - | `3.0.0` | web Used when contentType == file |
| `miniProgramInfo` | `MiniProgramInfo` | No | - | `3.0.0` | miniProgramInfo Used when contentType == miniProgram, and the share channel must be WeChat. |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `() => void` | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### 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` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Referenced Types

##### `interface` MiniProgramInfo

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `userName` | `string` | `3.0.0` | Username |
| `path` | `string` | `3.0.0` | Mini program page path |
| `hdImagePath` | `string` | `3.0.0` | Image URL |
| `withShareTicket` | `boolean` | `3.0.0` | Whether to include the share ticket |
| `miniProgramType` | `number` | `3.0.0` | Mini Program version type, corresponds to the miniProgramType field of the underlying sharing object |
| `webPageUrl` | `string` | `3.0.0` | Mini App URL |


### Valid Values

##### `type` valid values

| Value | Description |
| --- | --- |
| `"WeChat"` | WeChat |
| `"Message"` | SMS |
| `"Email"` | Email |
| `"More"` | More system share options (invoke system share) |

##### `contentType` valid values

| Value | Description |
| --- | --- |
| `"text"` | Text |
| `"image"` | Image |
| `"file"` | File |
| `"web"` | Web page URL |
| `"miniProgram"` | WeChat Mini Program share content |


### Examples

#### Demo

```tsx
import { share } from '@ray-js/ray'

share({
  type: "WeChat",
  title: "xx",
  message: "xx",
  contentType: "text",
  recipients: [],
  imagePath: "xx",
  filePath: "xx",
  webPageUrl: "xx",
  miniProgramInfo: {},
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
