---
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

> ⚡ **支持 Promise 调用** — 不传 success / fail / complete 回调时，该方法返回 Promise。

### 描述

按指定分享渠道分享文本、图片、文件、网页或小程序内容

### 参数

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `type` | `"WeChat" \| "Message" \| "Email" \| "More"` | 否 | `'WeChat'` | `3.0.0` | 分享渠道，未传时默认 WeChat；可选值：WeChat、Message、Email、More |
| `title` | `string` | 是 | - | `3.0.0` | title 标题 |
| `message` | `string` | 是 | - | `3.0.0` | message 文本内容 |
| `contentType` | `"text" \| "image" \| "file" \| "web" \| "miniProgram"` | 否 | `'text'` | `3.0.0` | contentType 内容类型 |
| `recipients` | `string[]` | 否 | - | `3.0.0` | recipients 邮件收件人/短信接收人 |
| `imagePath` | `string` | 否 | - | `3.0.0` | imagePath 图片路径 |
| `filePath` | `string` | 否 | - | `3.0.0` | 文件分享路径，contentType == file 时使用，未传会导致文件分享失败 |
| `webPageUrl` | `string` | 否 | - | `3.0.0` | web 当 contentType == file 时候使用 |
| `miniProgramInfo` | `MiniProgramInfo` | 否 | - | `3.0.0` | miniProgramInfo 当 contentType == miniProgram 时候使用，且分享渠道必须是微信。 |
| `complete` | `() => void` | 否 | - | - | 接口调用结束的回调函数（调用成功、失败都会执行） |
| `success` | `() => void` | 否 | - | - | 接口调用成功的回调函数 |
| `fail` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用失败的回调函数 |

#### fail 回调参数

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorMsg` | `string` | 错误信息 |
| `errorCode` | `string \| number` | 错误码 |
| `innerError` | `Object` | 错误扩展 |

##### fail(params).innerError 的属性

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorCode` | `string \| number` | 错误扩展码 |
| `errorMsg` | `string` | 错误扩展信息 |


### 引用对象

##### `interface` MiniProgramInfo

| 属性 | 类型 | 最低版本 | 描述 |
| --- | --- | --- | --- |
| `userName` | `string` | `3.0.0` | 用户名称 |
| `path` | `string` | `3.0.0` | 小程序页面路径 |
| `hdImagePath` | `string` | `3.0.0` | 图片地址 |
| `withShareTicket` | `boolean` | `3.0.0` | 是否携带分享 ticket |
| `miniProgramType` | `number` | `3.0.0` | 小程序版本类型，对应底层分享对象的 miniProgramType 字段 |
| `webPageUrl` | `string` | `3.0.0` | 小程序地址 |


### 合法值

##### `type` 合法值

| 值 | 说明 |
| --- | --- |
| `"WeChat"` | 微信 |
| `"Message"` | 短信 |
| `"Email"` | 邮件 |
| `"More"` | 系统更多分享渠道（调用系统分享） |

##### `contentType` 合法值

| 值 | 说明 |
| --- | --- |
| `"text"` | 文本 |
| `"image"` | 图片 |
| `"file"` | 文件 |
| `"web"` | 网页地址 |
| `"miniProgram"` | 微信小程序分享内容 |


### 示例代码

#### 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);
  },
});
```
