跳到主要内容
版本:v3

@capacitor/share

Share API 提供了在用户可能已安装的任何支持分享的应用中分享内容的方法。

Share API 适用于 iOS、Android 和 Web(使用新的 Web Share API),不过 Web 支持目前尚不完善。

安装

npm install @capacitor/share
npx cap sync

示例

import { Share } from '@capacitor/share';

await Share.share({
title: 'See cool stuff',
text: 'Really awesome thing you need to see right meow',
url: 'http://ionicframework.com/',
dialogTitle: 'Share with buddies',
});

每个平台使用不同的字段集,但您应该提供所有字段。

API

canShare()

canShare() => Promise<CanShareResult>

检查是否支持分享。

返回:

Promise<CanShareResult>

始于: 1.1.0


share(...)

share(options: ShareOptions) => Promise<ShareResult>

显示分享模态框,与其他应用分享内容

参数Type
options
ShareOptions

返回:

Promise<ShareResult>

始于: 1.0.0


接口

CanShareResult

属性Type描述始于
valueboolean是否支持分享。1.1.0

ShareResult

属性Type描述始于
activityTypestring接收分享操作的应用的标识符。某些情况下可能为空字符串。在 Web 上将是 undefined。1.0.0

ShareOptions

属性Type描述始于
titlestring为任何消息设置标题。如果是分享到邮件,这将是主题。1.0.0
textstring设置要分享的文本1.0.0
urlstring设置要分享的 URL,可以是 http、https 或 file:// URL1.0.0
dialogTitlestring设置分享模态框的标题。此选项仅在 Android 上受支持。1.0.0