gpt4 book ai didi

image - React Native-我们可以将图像和文本共享到whatsapp中吗?

转载 作者:行者123 更新时间:2023-12-04 04:15:07 24 4
gpt4 key购买 nike

我已经花了一个小时的时间来寻找一种使用 native react 将图像(如果可能的话,还有文本)发送/共享到whatsapp应用中的方法,

我已经阅读this question(在android中)和this question(使用链接)

在android上,可以将图像和文本发送到whatsapp,但是在响应 native 时,我看不到任何归档方法,

有人有主意吗?

最佳答案

对于大于0.56.0的本地 react 版本,该库中已经实现了社交共享功能,因此不再需要像react-native-share这样的额外库,并且它们可能无法维护。实际上,几个月前,我在较早版本的react-native中使用react-native-share库,并将相应的代码迁移到react-native实现中,该实现导出具有share方法的Share类,并且非常易于使用。

然后,您可以使用share方法共享数据,react-native会知道安装了手机的应用程序。在下图中,您可以看到共享屏幕在安装了WhatsApp应用程序的Android手机中的样子:
enter image description here

这就是在未安装任何应用的iOS模拟器中的样子:
enter image description here

在这里,您可以找到代码示例:

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消息中进行预览,并可以使用title或subject字段来添加文本。
-您可以共享base64文件网址,如下所示: url: 'data:image/png;base64,<base64_data>'

关于image - React Native-我们可以将图像和文本共享到whatsapp中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49484159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com