I tried to use CAMERA with Expo refer to these pages.
The pages are written “you can use CAMERA on web”(checkmark). but I can not use CAMERA becouse Permissions.askAsync() is allways staus == denied on web (iOS and Android are OK, return granted)
https://docs.expo.io/versions/v36.0.0/sdk/camera/
https://docs.expo.io/versions/latest/sdk/permissions/
How to use CAMERA on web? or can not yet?(the pages are misstaked)
The sample code
import React, { useState, useEffect } from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Camera } from 'expo-camera';
import * as Permissions from 'expo-permissions';
export default function App() {
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
useEffect(() => {
(async () => {
// const { status } = await Camera.requestPermissionsAsync();
const { status } = await Permissions.askAsync(Permissions.CAMERA);
alert(status);
setHasPermission(status === 'granted');
})();
}, []);
if (hasPermission === null) {
return <Text>Null</Text>;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
return (
<View style={{ flex: 1 }}>
<Camera style={{ flex: 1, width: 500, height: 500 }} type={type}>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
}}>
<TouchableOpacity
style={{
flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}>
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' }}> Flip </Text>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}