【问题标题】:Want to share multiple images with separate caption to each image Whatsapp, react native share想要与每个图像 Whatsapp 共享多个带有单独标题的图像,反应原生共享
【发布时间】:2021-07-05 01:59:08
【问题描述】:

我正在使用 React Native Share 库,一个不错的, 我只是需要一点帮助,

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

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

假设,如果有 5 张图片,那么 5 张图片的标题不一样。

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

这是我的代码

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

我附上了当前情况截图..

image 1 on whatsapp image 2 on whatsapp

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

谢谢。

【问题讨论】:

  • 你能分享一下你到目前为止尝试过的代码吗?
  • 嗨,我正在尝试为每个图像共享多个带有单独标题的图像,这是我的代码,它向每个图像发送相同的标题 var imgs=[img1,img2,img3]; let shareImage = { 标题:message 1,//字符串消息:message 1,//字符串 urls:imgs,主题:“图像”}; Share.open(shareImage).catch(err => console.log(err));
  • 你能给我代码 sn-p,不要在评论部分粘贴代码.. 示例:expo snap - snack.expo.io for react native 或 codeSandbox - codesandbox.io/s/dark-snow-b1b4g for react js
  • 好的,我现在就这样做
  • 我在世博会上成功了,我把我的代码放在一个函数中,我正在使用 react-native-share snack.expo.io/@msh1931/authentic-yogurt

标签: react-native


【解决方案1】:

我已经创建了使用react-native-share共享多个或单个图像的工作示例

CheckOut ExpoSnack Here

在每个方法之前添加 cmets 它将做什么以及需要替换什么。

// 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 Share Docs

const shareOptions = {
    title: 'Share multiple files example',
    urls: ["file..///","file..///","file..///"],
    failOnCancel: false,
};

【讨论】:

  • 感谢您的回答,它在我这边也可以正常工作,但问题是当我将 3 个文件共享到 whatsapp 时,它会共享 3 个文件,其中包含相同的消息,所有图像上的标题相同。但我需要在 whatsapp 上为每张图片发送不同的标题
  • 我还没有看到根据文档使用 react-native-share 为每个图像共享多个带有单独标题的图像。我在官方 github repo 中看到了一个未解决的问题,检查一下 -github.com/react-native-share/react-native-share/issues/995
  • 是的,这个问题也是我开的,我在等版主谢谢
  • 是的,我知道是你在 git 中打开了问题(由标题识别):) 无论如何,如果你在 github 中得到任何回复,请标记我 @klakshman318。
  • 好的伙计,我会在收到任何回复时标记你,仍在等待任何版主。谢谢
猜你喜欢
  • 2018-02-27
  • 2014-09-05
  • 2019-01-28
  • 1970-01-01
  • 2013-12-23
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多