ios - 未定义不是一个对象(评估'CameraManager.Aspect') - 反应原生
问题描述
我得到这个错误。当我尝试运行相机时,我在 Windows 10 中并在 iphone 6 plus 中使用 expo sumulator。我尝试按照本教程中的步骤进行操作:
1 - npm install react-native-camera --save
2 - 在 XCode 中,在项目导航器中,右键单击库 ➜ 将文件添加到 [您的项目名称]
3 - 转到 node_modules ➜ react-native-camera 并添加 RNCamera.xcodeproj
4 - 在 XCode 的项目导航器中,选择您的项目。将 libRNCamera.a 添加到项目的构建阶段 ➜ 将二进制文件与库链接
5 - 单击项目导航器中的 RNCamera.xcodeproj 并转到构建设置选项卡。确保打开“全部”(而不是“基本”)。在 Search Paths 部分,查找 Header Search Paths 并确保它包含 $(SRCROOT)/../../react-native/React 和 $(SRCROOT)/../../../React -将两者都标记为递归。
问题是我在 Windows 和 Windows XCODE 中不存在。我如何在 Windows 中解决这个问题?
请给我一些帮助。谢谢你...
我的代码是:
import React, { Component } from 'react';
import {Text, View,TouchableOpacity,TouchableHighlight} from 'react-native';
import Camera from 'react-native-camera';
const myStyle = {
container: {
flex: 1,
flexDirection: 'row',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
},
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
color: 'red',
padding: 10,
margin: 40
}
};
export default class CameraAcess extends Component {
constructor(props){
super (props);
this.state = {hasCameraPermission: null, type: Camera.Constants.Type.back,};
}
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ hasCameraPermission: status === 'granted' });
}
render() {
const {container,capture,preview} = myStyle;
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View/>;
} else if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
} else {
return (
<View style={{ flex: 1 }}>
<Camera style={{ flex: 1 }} type={this.state.type}>
<View style={{flex: 1, backgroundColor: 'transparent', flexDirection: 'row', justifyContent:'space-between'}}>
<TouchableOpacity style={{flex: 0.1, alignSelf: 'flex-end', alignItems: 'center',}}
onPress={() => {this.setState({type: this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front : Camera.Constants.Type.back,});}
}>
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>{' '}Flip{' '}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => {this.props.navigator.push({id: 'MenuPrincipal'});}}
style={{alignSelf: 'flex-end', alignItems: 'center', backgroundColor:'transparent'}}>
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' ,}}>[Back]</Text>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
}
}