【问题标题】:Share images to social media using react native使用 React Native 将图像分享到社交媒体
【发布时间】:2019-08-24 19:32:18
【问题描述】:

我正在开发一个反应原生应用程序。我想将我从 Firebase 存储中获取并在应用程序中列出的选定图像分享到 WhatsApp 等社交媒体。为此,我使用了一个名为

的 npm 包

反应原生分享

。使用它我可以共享文本但没有图像。官方页面告诉我应该先将图像转换为base64,我已经这样做了,应用程序开始崩溃。谁能告诉我怎么做。

【问题讨论】:

  • 你能提供到目前为止你做了什么吗?示例代码或sn-p?

标签: image firebase react-native share social-media


【解决方案1】:

您不再需要使用react-native-share。使用原生的Share 组件。

查看此帖子:React Native - can we share an image and text into whatsapp?

这里你可以找到一个代码示例:

import React, { Component } from 'react';
import {
  Share,
  Text,
  TouchableOpacity
} from 'react-native';

const shareOptions = {
  title: 'Title',
  message: 'Message to share', // Note that according to the documentation at least one of "message" or "url" fields is required
  url: 'www.example.com',
  subject: 'Subject'
};

export default class ShareExample extends React.Component {

  onSharePress = () => Share.share(shareOptions);

  render(){
    return(
      <TouchableOpacity onPress={this.onSharePress} >
        <Text>Share data</Text>
      </TouchableOpacity>
    );
  }
}

最后,您必须选择发送图像+文本消息的选项: - 您可以使用 shareOptions 的 url 字段添加图像的远程 URI,以便可以在 WhatsApp 消息中预览,并将标题或主题字段添加到添加文本。 - 你可以像这样分享一个base64文件的url:url: 'data:image/png;base64,'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多