This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 分享
一个用于实现文件共享的库。
Android
iOS
Web
Included in Expo Go
expo-sharing 允许你直接与其他兼容的应用共享文件。
Web 上的共享限制
expo-sharing的 web 版本基于 Web Share API,但该 API 目前在浏览器中的支持仍然 非常有限。在调用之前,请务必使用Sharing.isAvailableAsync()检查该 API 是否可用。- Web 端需要 HTTPS:Web Share API 仅在网页通过 https 提供服务时才可用。请使用
npx expo start --tunnel运行你的应用以启用它。 - Web 端不支持本地文件共享:通过 URI 共享本地文件在 Android 和 iOS 上可行,但在 web 上不可行。你不能在 web 上通过 URI 共享本地文件——你需要先将它们上传到某处,然后共享该 URI。
从其他应用共享到你的应用
目前 expo-sharing 仅支持从你的应用共享到其他应用,你无法在原生平台上注册你的应用,使其通过原生共享对话框接收共享内容。你可以在 相关功能请求 中了解更多。你可以在 Xcode 和 Android Studio 中手动设置此功能,并创建一个 Expo 配置插件,以继续使用 Expo Prebuild。
安装
Terminal
If 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.
Returns:
Promise<boolean>A promise that fulfills with true if the sharing API can be used, and false otherwise.
Opens action sheet to share file to different applications which can handle this type of file.
Returns:
Promise<void>