pgz*_*m29 5 javascript share whatsapp react-native react-native-ios
我正在开发一个 React Native 应用程序,我的需求之一是能够通过 Whatsapp 共享 png 图像(从 svg 创建)以及消息中的一些文本。我已经使用react-native-share在Android上实现了这一点,但是当我在iOS上尝试时,消息中填充了提供的文本,但图像被忽略。我也尝试过分享,但结果是一样的。
我尝试过直接共享 base64 图像(data:image/png;base64, image_data)以及保存创建的图像并将路径添加为 url,但结果始终相同。
在 iOS 上(同时使用 React-native-share 和 Share)实现此功能的唯一方法是省略该消息,但需求中需要文本。
有办法实现这一点吗?
版本:
顺便说一句,Twitter、电子邮件、短信和其他一些应用程序上的共享过程运行正常。
代码示例:
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)
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2995 次 |
| 最近记录: |