使用库 react-native-camera
制作一个用相机进行文本识别的演示,但相机没有打开
完成所有这些步骤:
npm install react-native-camera --save
react-native link react-native-camera
- 转到 node_modules ➜ react-native-camera 并添加 RNCamera.xcodeproj
- 展开 RNCamera.xcodeproj ➜ Products 文件夹
在 XCode 的项目导航器中,选择您的项目。将 libRNCamera.a 添加到项目的构建阶段 ➜ 链接二进制文件 图书馆
在项目导航器中单击 RNCamera.xcodeproj,然后转到“build设置”选项卡。确保“全部”已打开(而不是 '基本')。
在 Search Paths 部分,查找 Header Search Paths 并确保它同时包含 $(SRCROOT)/../../react-native/React 和 $(SRCROOT)/../../../React - 将两者标记为递归
import { RNCamera } from 'react-native-camera'; camerascan(){ console.log("camscan=====") return( <RNCamera ref={ref => { this.camera = ref; }} defaultTouchToFocus mirrorImage={false} captureAudio={false} style={{ flex: 1, justifyContent: 'space-between', alignItems: 'center', height: Dimensions.get('window').height, width: Dimensions.get('window').width, }} permissionDialogTitle={'Permission to use camera'} permissionDialogMessage={'We need your permission to use your camera phone'} > <View style={{ height: 56, backgroundColor: 'transparent', alignSelf: 'flex-end', }} > <TouchableOpacity onPress={this.takePicture.bind(this)}> <Text style={styles.capture}> [CAPTURE CARD]</Text> </TouchableOpacity> </View> </RNCamera> ); } takePicture = async function() { console.log("takePicture=====") if (this.camera) { // const options = { quality: 0.5, base64: true }; // const data = await this.camera.takePictureAsync(options) const data = await this.camera.takePictureAsync(); console.warn('takePicture ', data); // this.detectText(data.base64) } };
没有错误,但相机没有打开。
最佳答案
Done gave the runtime permissions for camera
import Permissions from 'react-native-permissions'
componentDidMount()
{
this.determinePermission();
}
determinePermission(){
Permissions.request('camera', { type: 'always' }).then(response => {
this.setState({ locationPermission: response })
})
}
关于ios - Ios 中的 React-native-camera 不工作不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56339624/