跳到主要内容
版本:v2

Share

Share API 提供了分享内容到用户已安装且支持分享功能的应用的方法。

Share API 支持 iOS、Android 和 Web 平台(使用新的 Web Share API),但目前 Web 平台的支持尚不完善。

示例

import { Plugins } from '@capacitor/core';
const { Share } = Plugins;

let shareRet = 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

share(...)

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

显示分享模态框,用于将应用中的内容分享到其他应用

参数类型
options
ShareOptions

返回值: Promise<any>


Interfaces

ShareOptions

属性类型描述
titlestring设置消息标题。如果分享到电子邮件,该字段将作为邮件主题
textstring设置要分享的文本内容
urlstring设置要分享的 URL,可以是 http、https 或文件 URL
dialogTitlestring设置分享模态框的标题(仅限 Android 平台)