通过 Whatsapp 和 Facebook React Native 分享图片

React Native Share Image via Whats App and Facebook

我正在尝试从 url 下载图片,然后通过 whats app 和其他社交媒体将其作为图片格式分享,我尝试了一些方法但我做不到,我的代码如下:

let filePath = null;
        const configOptions = {
            fileCache: true,
        };
        RNFetchBlob.config(configOptions)
            .fetch('GET', url)
            .then(async resp => {
                filePath = resp.path();
                let options = {
                    url: filePath 
                };
                await Share.open(options);
                await RNFS.unlink(filePath);
            });

我也试过了

RNFetchBlob.fetch("GET",url,{
                    Authorization : 'Bearer access-token...',
                  })
                .then(resp => {
                    console.log(resp)
                  let shareImageBase64 = {
                    title: "React Native",
                    message: "Hola mundo",
                    url: `data:image/png;base64,` + resp.base64(),

                  };
                  Share.open(shareImageBase64);
                })

确实打开了分享选项,但是没有图片,只能分享消息。

这是 github 中的未解决问题,仅在 IOS 与 whats app 共享时才会出现该问题。问题是 shareImageBase64 下的消息覆盖了 url 并且您仅共享该消息,解决方法是删除该消息并且您将能够成功共享您的图像。