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 Config Plugin 以继续使用 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 |