gpt4 book ai didi

javascript - 分享在 native android/ios 中不起作用?

转载 作者:行者123 更新时间:2023-12-04 02:05:36 25 4
gpt4 key购买 nike

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

代码:

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>

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

enter image description here

最佳答案

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.

像这样

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

关于javascript - 分享在 native android/ios 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53045415/

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