Expo 分享
一个用于实现文件分享的库。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
expo-sharing 允许你直接与其他兼容的应用共享文件。
Web 上的共享限制
- Web 版
expo-sharing构建在 Web Share API 之上,而该 API 目前的 浏览器支持非常有限。在调用之前,请务必先使用Sharing.isAvailableAsync()检查该 API 是否可用。 - Web 上需要 HTTPS:Web Share API 仅在页面通过 https 提供服务时才可在 web 上使用。请使用
npx expo start --tunnel运行你的应用以启用它。 - Web 上不支持本地文件共享:通过 URI 共享本地文件在 Android 和 iOS 上可行,但在 web 上不行。你不能在 web 上通过 URI 共享本地文件——你需要先把它们上传到某个位置,然后共享该 URI。
从其他应用共享到你的应用
目前 expo-sharing 仅支持从你的应用共享到其他应用,你无法在原生平台上注册你的应用,使其通过原生共享对话框接收共享内容。你可以在 相关功能请求 中了解更多。你可以在 Xcode 和 Android Studio 中手动设置此功能,并创建一个 Expo 配置插件,以继续使用 Expo Prebuild。
安装
- npx expo install expo-sharingIf you are installing this in an existing React Native app, make sure to install expo in your project.
API
import * as Sharing from 'expo-sharing';
Methods
Determine if the sharing API can be used in this app.
Promise<boolean>A promise that fulfills with true if the sharing API can be used, and false otherwise.
| Parameter | Type | Description |
|---|---|---|
| url | string | Local file URL to share. |
| options(optional) | SharingOptions | A map of share options. Default: {} |
Opens action sheet to share file to different applications which can handle this type of file.
Promise<void>Types
| Property | Type | Description |
|---|---|---|
| anchor(optional) | {
height: number,
width: number,
x: number,
y: number
} | Only for: iOS set the anchor point for iPad |
| dialogTitle(optional) | string | Only for: Android Web Sets share dialog title. |
| mimeType(optional) | string | Only for: Android Sets |
| UTI(optional) | string |