gpt4 book ai didi

javascript - react-native-share promise 拒绝错误

转载 作者:搜寻专家 更新时间:2023-11-01 04:34:54 25 4
gpt4 key购买 nike

我正在使用来自 https://github.com/EstebanFuentealba/react-native-shareshareSingle()在我的应用程序中获取 facebook 共享功能。

我按照文档编写了下面的代码,但它抛出:

Possible Unhandled Promise Rejection error. TypeError: undefined is not an object

[exp] undefined 不是一个对象(评估'_reactNative.NativeModules.RNShare.shareSingle')

import React, {Component} from 'react';
import {StyleSheet, View} from 'react-native';
import Share, {ShareSheet, Button} from 'react-native-share';

export default class PreviewImage extends Component {
constructor(props) {
super(props);
this.state = {
visible: false
}
}

onCancel = () => {
this.setState({visible:false});
}

onOpen = () => {
this.setState({visible:true});
}

render() {
let shareOptions = {
title: "React Native",
message: "Hola mundo",
url: "http://facebook.github.io/react-native/"
};

return (
<View style={styles.container}>
<View style={styles.shareImageButton}>
<Button
buttonStyle={{
backgroundColor: "rgba(92, 99,216, 1)",
borderColor: "transparent",
borderWidth: 0,
borderRadius: 5
}}
onPress={() => this.onOpen()}
textStyle={{textAlign: 'center'}}
title={'Share'}/>
</View>
<ShareSheet
visible={this.state.visible}
onCancel={this.onCancel}
>
<Button iconSrc={{ uri: FACEBOOK_ICON }}
onPress={
() => {
this.onCancel();
setTimeout(() => {
Share.shareSingle(Object.assign({}, shareOptions, {"social": "facebook"})).catch(err => console.log(err));
}, 300);
}
}
>
Facebook
</Button>
</ShareSheet>
</View>
)
}
}

// facebook icon
const FACEBOOK_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAMAAAANIilAAAAAYFBMVEUAAAAAQIAAWpwAX5kAX5gAX5gAX5gAXJwAXpgAWZ8AX5gAXaIAX5gAXpkAVaoAX5gAXJsAX5gAX5gAYJkAYJkAXpoAX5gAX5gAX5kAXpcAX5kAX5gAX5gAX5YAXpoAYJijtTrqAAAAIHRSTlMABFis4vv/JL0o4QvSegbnQPx8UHWwj4OUgo7Px061qCrcMv8AAAB0SURBVEjH7dK3DoAwDEVRqum9BwL//5dIscQEEjFiCPhubziTbVkc98dsx/V8UGnbIIQjXRvFQMZJCnScAR3nxQNcIqrqRqWHW8Qd6cY94oGER8STMVioZsQLLnEXw1mMr5OqFdGGS378wxgzZvwO5jiz2wFnjxABOufdfQAAAABJRU5ErkJggg==";

const styles = StyleSheet.create({
container: {
flex: 1,
},
shareImageButton: {
flex: 1,
justifyContent: 'center',
}
});

在此表示感谢。

请注意 Share.open() 对我来说工作得很好。

我的包.json

{
"name": "TrashCan",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.11.1",
"jest-expo": "25.0.0",
"react-test-renderer": "16.2.0"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"axios": "^0.18.0",
"expo": "^25.0.0",
"react": "16.2.0",
"react-native": "0.52.0",
"react-native-elements": "^0.19.0",
"react-native-share": "^1.0.26",
"react-navigation": "^1.1.2",
"react-redux": "^5.0.7",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"react-native-animate-number": "^0.1.2"
}
}

最佳答案

我认为您需要将 RNShare.xcodeproj 添加到项目的库中,然后转到 General->Linked Frameworks and Libraries,添加 libRNShare.a 。它解决了我的问题。

关于javascript - react-native-share promise 拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49082623/

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