想要共享多个图像,每个图像都有单独的标题 Whatsapp,反应本机共享

2024-01-08

我正在使用 React Native Share 库,一个很好的库, 我只需要一点点帮助

它正在共享具有相同标题的多个图像,

我只想分享多个图像,每个图像都有单独的消息(标题),

假设,如果有 5 张图像,那么 5 张图像的标题是不同的,不相同的。

在当前情况下,它共享 5 张带有相同消息的图像(标题)

这是我的代码

var imgs=["base64IMAGE1...///","base64IMAGE2..///","base64IMAGE3..///"]; 让共享图像 = { 标题:“标题”, 消息:“这是需要单独发送到每个图像的消息”, 网址:abcc, 主题:“图像” }; Share.open(shareImage).catch(err => console.log(err));

我附上了目前情况的截图..

Whatsapp 上的图片 1 https://i.stack.imgur.com/diPd6.jpg Whatsapp 上的图 2 https://i.stack.imgur.com/N04qn.jpg

所有发送的标题都相同,我只是发送带有单独消息的多个图像

谢谢。


我创建了工作示例来共享多个或单个图像反应本机共享 https://react-native-share.github.io/react-native-share/docs/share-open

在这里查看 ExpoSnack https://snack.expo.io/@klakshman318/sharemultiorsingleimagesrn

在每个方法之前添加注释,说明它将做什么以及需要替换什么。

// multiple images share example
const shareMultipleImages = async () => {
    const shareOptions = {
        title: 'Share multiple files example',
        // here replace base64 data with your local filepath
        // base64 with mimeType or path to local file
        urls: [base64ImagesData.image1, base64ImagesData.image2],
        failOnCancel: false,
    };

    // If you want, you can use a try catch, to parse
    // the share response. If the user cancels, etc.
    try {
        const ShareResponse = await Share.open(shareOptions);
        setResult(JSON.stringify(ShareResponse, null, 2));
    } catch (error) {
        console.log('Error =>', error);
        setResult('error: '.concat(getErrorString(error)));
    }
};

您可以在 shareMultipleImage 方法中添加本地文件路径,如下所示

urls:您要共享的 Base64 字符串数组。使用 mimeType 或本地文件路径的 base64 (Array[string])

React Native 共享文档 https://react-native-share.github.io/react-native-share/docs/share-open

const shareOptions = {
    title: 'Share multiple files example',
    urls: ["file..///","file..///","file..///"],
    failOnCancel: false,
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

想要共享多个图像,每个图像都有单独的标题 Whatsapp,反应本机共享 的相关文章

随机推荐