我尝试使用Camera
在我的react-native
应用程序中实现react-native-camera
,但它似乎不起作用。当我运行react-native run-android
空白屏幕时出现任何错误。这是我的代码,
import Camera from 'react-native-camera';
<Camera
style={Styles.preview}
aspect={Camera.constants.Aspect.fill}
ref={cam => { this.camera = cam; }}
/>
const Styles = {
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
}
};
答案 0 :(得分:0)
您是否设置了权限以便应用可以使用相机?如果您还没有设置权限,则可以如下所示:
要启用视频录制功能,您必须将以下代码添加到AndroidManifest.xml
:
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在/ios/yourProject/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>NSCameraUsageDescription</key>
<string>We need your beautiful camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We're only saving to temp, promise</string>
</dict>
</plist>
答案 1 :(得分:0)
我遇到了类似的问题,发现我需要手动设置iOS的标头路径,如README here中所述。希望对你有帮助!