React-Native ENOENT:没有这样的文件或目录,在Xcode中打开'assets-library://asset/asset.jpg'

时间:2018-07-17 05:59:00

标签: ios xcode react-native react-native-ios

您好,在我的react-native应用程序中使用react-native-fs从iPhone上传图片时。我遇到错误了。

enter image description here

如何解决上述问题。

1 个答案:

答案 0 :(得分:1)

我通过在文件中添加此 captureTarget = {Camera.constants.CaptureTarget.disk} 行代码来解决上述问题。

import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View
} from 'react-native';
import Camera from 'react-native-camera';
import RNFS from 'react-native-fs';

export default class App extends Component {
    render() {
        return (
            <View style={styles.container}>
                <View style={styles.titlebar}>
                    <Text style={styles.title}>Welcome {this.props.navigation.getParam('FirstName', '')}</Text>
                </View>
                <Camera
                    ref={(cam) => {
                        this.camera = cam;
                    }}
                    type={'front'}
                    style={styles.preview}
                    aspect={Camera.constants.Aspect.fill}
                    captureQuality={Camera.constants.CaptureQuality.low}
                    captureTarget={Camera.constants.CaptureTarget.disk}
                >
                    <View>
                        <View style={styles.buttoncontainer}>
                            {
                                this.props.navigation.getParam('LogType', '') &&
                                <Text style={styles.in} onPress={this.takePicture.bind(this)}>IN</Text>
                            }
                            {!this.props.navigation.getParam('LogType', '') &&
                            <Text style={styles.out} onPress={this.takePicture.bind(this)}>OUT</Text>
                            }
                        </View>
                    </View>
                </Camera>
            </View>
        );
    }

    takePicture() {
        this.camera.capture()
            .then((data) =>
                this.ServiceCall(data)
            )
            .catch(err => console.error(err));
    }

}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'white'
    },
    title: {
        flex: 1,
        alignSelf: 'center',
        fontSize: 30,
        color: 'black',
        backgroundColor: 'white'
    },
    titlebar: {
        flexDirection: 'row',
        backgroundColor: 'white',
        paddingTop: 10,
        paddingBottom: 10,
        paddingLeft: 5
    },
    buttoncontainer: {
        flexDirection: 'row',
    },
    preview: {
        flex: 1,
        justifyContent: 'flex-end',
        alignItems: 'center'
    },
    in: {
        fontSize: 30,
        backgroundColor: 'green',
        marginBottom: 20,
        padding: 20,
        color: 'white',
        borderRadius: 10,
        textAlign: 'center'
    },
    out: {
        fontSize: 30,
        padding: 20,
        backgroundColor: 'red',
        marginBottom: 20,
        color: 'white',
        borderRadius: 10,
        textAlign: 'center'
    },
});
强文本