简体   繁体   English

在 React Native 中将数据共享到社交媒体

[英]Sharing data to social media in React native

I have an app in which i want to share specific data to social media like facebook,twitter,pinterest etc once the user clicks on the social icon.我有一个应用程序,一旦用户点击社交图标,我想在其中将特定数据共享到社交媒体,如 facebook、twitter、pinterest 等。 I have already used react native link which sends me to the pages of these platforms.我已经使用了 react native 链接,它将我发送到这些平台的页面。 But i want to share data to these once clicked.但是我想在点击后与这些共享数据。 I have done this for whatsapp which is like this:我已经为 whatsapp 做了这个,就像这样:

 <TouchableOpacity onPress={() => { let url = 'whatsapp://send?text=${hello}&phone=${01753362960}'; Linking.openURL(url).then((data) => { console.log('open whatsapp', data) }).catch(() => { console.log('App not installed') }); }} > <Icon name='logo-whatsapp' style={{color: '#395894', fontSize: 30, marginRight: 10}}/> </TouchableOpacity>
I have done this for twitter also. 我也为推特做过这件事。 But when that icon is clicked it shows the alert that the app is not installed although it was installed on my device.It was like: 但是当单击该图标时,它会显示该应用程序未安装的警报,尽管它已安装在我的设备上。它就像:

 let url = 'twitter://send?text=hello this is checked'

How can i do this for other social media platforms?我如何为其他社交媒体平台执行此操作?

对于推特,请使用这个,

let url = 'twitter://post?message=${yourMsg}'

I would do it this way: https://facebook.github.io/react-native/docs/share我会这样做: https : //facebook.github.io/react-native/docs/share

This way the user can chose what app he wants to share to based on apps installed on users device通过这种方式,用户可以根据用户设备上安装的应用程序选择他想要共享的应用程序

react-native-share is a good package to use for making some stuff share at different platforms. react-native-share 是一个很好的包,用于在不同平台上共享一些东西。 Back in early 2019 this package wasn't this much mature, but now it's really usefull.早在 2019 年初,这个包还没有那么成熟,但现在它真的很有用。

https://github.com/react-native-community/react-native-sharehttps://github.com/react-native-community/react-native-share

Have a look at here.看看这里。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM