我正在开发一个本机应用程序,我的需求之一是能够通过Whatsapp共享png图像(从svg创建)以及消息中的一些文本。我已经使用react-native-share在Android上实现了此功能,但是当我在iOS上尝试使用该功能时,该消息将使用提供的文本填充,但图像将被忽略。我也曾尝试使用react-native的Share,但结果是相同的。
我尝试了直接共享base64图像(data:image / png; base64, image_data ),以及保存创建的图像并添加路径作为url ,但结果始终相同。
在iOS上同时使用react-native-share和Share的唯一方法是忽略消息,但要求中输入文本。
有没有办法做到这一点?
版本:
请注意,Twitter,电子邮件,SMS和其他一些应用程序上的共享过程正常运行。
代码示例:
const base64Data = this.state.uri
const dir = `${RNFS.DocumentDirectoryPath}/tmp_${moment().valueOf()}.png`
RNFS.writeFile(dir, base64Data, 'base64').then(async () => {
const options = {
url: Platform.OS === 'android' ? `file://${dir}` : dir,
message: '' // By omitting the message, whatsapp shows the image
}
try {
await Share.open(options)
// Delete file when share action is completed
await RNFS.unlink(dir)
} catch (error) {
console.log('error', error)
}
}).catch((err) => {
console.log(err.message)
})