【问题标题】:Share file from url with React Native使用 React Native 从 url 共享文件
【发布时间】:2019-12-22 18:12:54
【问题描述】:

我已经设法使用{ Share } from 'react-native' 与其他应用程序(例如 WhatsApp)发送消息。

现在,我想从 url (mp3) 共享一个文件,而不仅仅是 url 链接。 我没有找到案例,我尝试了这样的事情,但它没有奏效:

react import { Share } from 'react-native'

Share.share({
                  url: "https//www.website.com/mymp3.mp3",
            })

【问题讨论】:

    标签: android ios react-native share


    【解决方案1】:
    Try this,
    
     in your render(){
    
    <Button onPress={() => this.onClickShare()}> Share </Button>
    
    }
    
    your custom function,
    
    onClickShare = async () => {
        try {
          const result = await Share.share({
            message:
              "https//www.website.com/mymp3.mp3",
          });
        } catch (error) {
          alert(error.message);
        }
      };
    

    其实很简单..... pn - 你可以写 url: prop 通过检查 platform==="ios" 代替 message,就像 ios 一样,在android中它会自动获取一个链接。

    【讨论】:

    • 感谢您的帮助!但它共享链接 https//www.website.com/mymp3.mp3,而不是直接共享 mp3 文件。不知道有没有可能。
    猜你喜欢
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 2017-01-31
    • 1970-01-01
    相关资源
    最近更新 更多