react-native-share承诺拒绝错误 [英] react-native-share promise rejection error

查看:133
本文介绍了react-native-share承诺拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using shareSingle() from https://github.com/EstebanFuentealba/react-native-share to get the facebook share functionality in my application.

我在文档后面编写了下面的代码,但它抛出了可能未处理的Promise Rejection错误 .TypeError:undefined不是对象

I wrote the code below following the documentation, but it throws "Possible Unhandled Promise Rejection error. TypeError: undefined is not an object"

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

[exp] undefined is not an object (evaluating '_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',
    }
});

这里的潜在客户表示赞赏。

Leads here is appreciated.

请注意,Share.open()对我来说效果很好。

Please note that Share.open() works perfectly fine for me.

我的package.json

My package.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 添加到项目库,然后转到常规 - >链接的框架和库,添加 libRNShare.a
这解决了我的问题。

I think you need to add RNShare.xcodeproj to your Project' Libraries and then go to General->Linked Frameworks and Libraries, add libRNShare.a. It's fixed my problem.

这篇关于react-native-share承诺拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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