分享在本机 android/ios 中不起作用? [英] Share not working in react native android/ios?

查看:37
本文介绍了分享在本机 android/ios 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何共享将在本机移动应用程序 Web 浏览器中打开的 pdf 文件链接或图像链接.我添加了一个共享按钮,但是当用户点击它时,它会打开共享菜单选项的位置,如 WhatsApp、Gmail、消息等.但是当点击 WhatsApp 时,它不会发送任何内容,为什么会这样?我是否需要在我的本机 Android 应用程序中使用 Gmail、WhatsApp API

代码:

import {文本,看法,样式表,按钮,动画,方面,滚动视图,图像,可触摸不透明度,链接,平台,分享来自'反应原生';//内部渲染onSharePress = (shareOptions) =>Share.share(shareOptions);常量共享选项 = {title: '下载手册',网址:小册子}//内部返回<视图样式={{paddingLeft: 10, marginRight: 20, flex: 1, flexDirection: 'row', justifyContent: 'flex-end'}}><TouchableOpacity onPress={() =>this.onSharePress(shareOptions)}><图标样式={{paddingLeft: 10}} name="md-share" size={25} color="black"/></TouchableOpacity></查看>

在下面的屏幕截图中,您可以看到它只是打开了共享选项菜单,但是当我单击某些平台时,未发送内容,即文件的 URL,我该怎么做?我错过了什么吗?

解决方案

Share.share(content, options) 分别接收 content 和 options 参数.

Share.share(content, options) 在 Android 和IOS.您基本上需要解析 Promise 或阅读响应来自它.

像这样

Share.share({message: '你的消息',网址:你的网址}).then(({action, activityType}) => {if(action === Share.sharedAction)console.log('分享成功');别的console.log('分享被取消');});

<块引用>

Promise 返回一个包含 action、activityType

的对象

如果用户关闭对话框,Promise 将通过动作是 Share.dismissedAction 否则动作是Share.sharedAction

How can I share pdf file link or image link which will open in react native mobile app web browser. I have added a share button but when the user clicks on it, it opens where to share menu options like WhatsApp, Gmail, messages, etc. But when clicking on WhatsApp it does not send any content why so? Do I need to make use of Gmail, WhatsApp API with my react native android app

code:

import {
  Text,
  View,
  StyleSheet,
  Button,
  Animated,
  Dimensions,
  ScrollView,
  Image,
  TouchableOpacity,
  Linking,
  Platform,
  Share
} from 'react-native';


// inside render

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

const shareOptions = {
   title: 'Download Brochure',
    url: brochure
}

// inside return 

<View style={{paddingLeft: 10, marginRight: 20, flex: 1, flexDirection: 'row', justifyContent: 'flex-end'}}>
    <TouchableOpacity onPress={() => this.onSharePress(shareOptions)}>
         <Icon style={{paddingLeft: 10}} name="md-share" size={25} color="black"/>
     </TouchableOpacity>
</View>

In screenshot below you can see it just opens the share options menu but when I click on some of the platform the content i.e the URL of the file is not sent how can I do that ? Am I missing something ?

解决方案

Share.share(content, options) receives content and options parameter separately.

Share.share(content, options) returns a Promise on both Android and IOS. You basically need to resolve the Promise or read the response from it.

Like so

Share.share(
{
  message: 'Your message',
  url: YourURL
}
).then(({action, activityType}) => {
if(action === Share.sharedAction)
  console.log('Share was successful');
else
  console.log('Share was dismissed');
});

Promise returns an object containing action, activityType

If the user dismissed the dialog, the Promise will be resolved with action being Share.dismissedAction else with action being Share.sharedAction

这篇关于分享在本机 android/ios 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆