在单个应用程序中反应本机共享

cha*_*les 4 react-native

在我的 react-native 应用程序中,我想与特定应用程序共享文本消息,例如 whatsapp 或短信应用程序,而不必先登陆所有社交应用程序的对话框。

例如,如果我按下分享按钮并直接调用 whatsapp。

我尝试使用react-native-share但它似乎不再起作用了。

小智 5

您可以使用链接它为您提供了一个通用界面来与传入和传出的应用程序链接进行交互

例如:

import React, { Component } from 'react';
import { Linking, Button } from 'react-native';

export class App extends Component {
  render() {
    return <Button
              onPress={() => {
                let url = 'whatsapp://send?text=Hola Mundo';
                Linking.openURL(url).then((data) => {
                  console.log('open whatsapp')
                }).catch(() => {
                  console.log('App not installed')
                });
              }}
              title="Whatsapp"
              color="#4FBE3C"/>;
  }
}
Run Code Online (Sandbox Code Playgroud)