是否可以使用 expo-sharing 共享文本消息和图像?
Is it possible to share both text message and image using expo-sharing?
Sharing.shareAsync(url, 选项)
打开操作 sheet 以将文件共享到可以处理此类文件的不同应用程序。
参数
url(字符串)-- 要共享的本地文件 URL。
选项 (object) --
选项图:
mimeType (string) -- 为 Intent 设置 mimeType(仅 Android)
dialogTitle(字符串)——设置共享对话框标题(Android 和 Web only)
UTI (string) -- (Uniform Type Identifier) 目标文件的类型 (iOS only)
这就是他们在页面上所说的。我没有看到任何与本地图像一起共享文本消息的选项。
有什么方法可以同时分享图片和短信吗?
根据文档,您应该可以像这样使用它 Android:
url = '<image-to-be-shared-local-url>';
messageText = 'Text that you want to share goes here';
const options = {
mimeType: 'image/jpeg',
dialogTitle: messageText,
};
Sharing.shareAsync(url, options);
但我建议使用 react-native-share
,因为它使用更广泛并且有更多选项供您试验。
Here is the library documentation
希望这对您有所帮助:)
react-native-share 仍然与 expo 不兼容。您必须使用 expo-sharing 或从 react-native 分享。
示例:
ShareMessage = async () => {
if (Platform.OS === "android") {
Share.share({
message: API.base_url + this.state.ShareProductName, // supporting android
url: this.state.share_images[0], // not supporting
title: this.state.ShareProductName,
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
} else if (Platform.OS === "ios") {
Share.share({
message:API.base_url + this.state.ShareProductName,
url: this.state.share_images[0],
title: this.state.ShareProductName, // not supporting
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
}
};
Sharing.shareAsync(url, 选项)
打开操作 sheet 以将文件共享到可以处理此类文件的不同应用程序。
参数 url(字符串)-- 要共享的本地文件 URL。 选项 (object) -- 选项图: mimeType (string) -- 为 Intent 设置 mimeType(仅 Android) dialogTitle(字符串)——设置共享对话框标题(Android 和 Web only) UTI (string) -- (Uniform Type Identifier) 目标文件的类型 (iOS only)
这就是他们在页面上所说的。我没有看到任何与本地图像一起共享文本消息的选项。 有什么方法可以同时分享图片和短信吗?
根据文档,您应该可以像这样使用它 Android:
url = '<image-to-be-shared-local-url>';
messageText = 'Text that you want to share goes here';
const options = {
mimeType: 'image/jpeg',
dialogTitle: messageText,
};
Sharing.shareAsync(url, options);
但我建议使用 react-native-share
,因为它使用更广泛并且有更多选项供您试验。
Here is the library documentation
希望这对您有所帮助:)
react-native-share 仍然与 expo 不兼容。您必须使用 expo-sharing 或从 react-native 分享。
示例:
ShareMessage = async () => {
if (Platform.OS === "android") {
Share.share({
message: API.base_url + this.state.ShareProductName, // supporting android
url: this.state.share_images[0], // not supporting
title: this.state.ShareProductName,
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
} else if (Platform.OS === "ios") {
Share.share({
message:API.base_url + this.state.ShareProductName,
url: this.state.share_images[0],
title: this.state.ShareProductName, // not supporting
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
}
};