我正试图通过iphone访问相机而我不知道该怎么做。
我有一个<button>
点击后我想在iphone上访问相机。
有人可以向我解释我该怎么办?
答案 0 :(得分:1)
使用import Camera from 'react-native-camera';
然后创建一个方法,
takePicture() {
this.camera.capture()
// some service action if you want to use...
.then(data => {
.........
// this is for vibrating device while taking photo
Vibration.vibrate();
..........
});
}
您需要添加权限
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
'title': 'Cool Photo App Camera Permission',
'message': 'Cool Photo App needs access to your camera ' +
'so you can take awesome pictures.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
alert("You can use the camera")
} else {
alert("Camera permission denied");
}
} catch (err) {
alert(err)
}
}
https://github.com/react-native-community/react-native-camera
这就是你需要做的......