React Native Camera Permission — Complete Guide
In this tutorial, you'll learn about React Native Camera Permission. We cover key concepts, practical examples, and best practices.
The Problem
Your app crashes when camera permission is denied, or the permission dialog shows a generic message.
Wrong Approach ❌
// Requesting permission without checking or rationale
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
Output: User denies permission. App doesn't explain why.
Right Approach ✅
import { Platform, Linking, Alert } from 'react-native';
import { check, request, PERMISSIONS, RESULTS, checkMultiple, requestMultiple } from 'react-native-permissions';
class CameraPermissionManager {
// Check current status
static async getCameraStatus(): Promise<string> {
if (Platform.OS === 'ios') {
return check(PERMISSIONS.IOS.CAMERA);
}
return check(PERMISSIONS.ANDROID.CAMERA);
}
// Request with rationale on Android
static async requestCameraPermission(): Promise<boolean> {
try {
const result = await request(
Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA
);
switch (result) {
case RESULTS.GRANTED:
return true;
case RESULTS.DENIED:
// User tapped "Deny" — can request again
Alert.alert(
'Camera Permission Needed',
'We need camera access to take photos. Please grant permission.',
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'Try Again', onPress: () => this.requestCameraPermission() },
]
);
return false;
case RESULTS.BLOCKED:
// User tapped "Deny" and "Never Ask Again"
Alert.alert(
'Camera Permission Blocked',
'Camera access is permanently blocked. Please enable it in Settings.',
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'Open Settings', onPress: this.openAppSettings },
]
);
return false;
case RESULTS.UNAVAILABLE:
// Device doesn't have camera
Alert.alert('Camera Not Available', 'This device does not support camera.');
return false;
default:
return false;
}
} catch (error) {
console.error('Permission error:', error);
return false;
}
}
// Multiple permissions (camera + microphone)
static async requestCameraAndMic(): Promise<boolean> {
const permissions = Platform.OS === 'ios'
? [PERMISSIONS.IOS.CAMERA, PERMISSIONS.IOS.MICROPHONE]
: [PERMISSIONS.ANDROID.CAMERA, PERMISSIONS.ANDROID.RECORD_AUDIO];
const results = await requestMultiple(permissions);
return Object.values(results).every(r => r === RESULTS.GRANTED);
}
static openAppSettings() {
Linking.openSettings();
}
}
// Usage in component
function CameraScreen() {
const [hasPermission, setHasPermission] = useState(false);
useEffect(() => {
CameraPermissionManager.getCameraStatus().then(status => {
if (status === RESULTS.GRANTED) {
setHasPermission(true);
}
});
}, []);
const handleOpenCamera = async () => {
const granted = await CameraPermissionManager.requestCameraPermission();
if (granted) {
setHasPermission(true);
// Open camera
}
};
return (
<View>
{hasPermission ? (
<CameraComponent />
) : (
<Button title="Grant Camera Access" onPress={handleOpenCamera} />
)}
</View>
);
}
// Info.plist messages (iOS)
// <key>NSCameraUsageDescription</key>
// <string>We need camera access to take profile photos</string>
// AndroidManifest.xml
// <uses-permission android:name="android.permission.CAMERA" />
Output: Proper permission flow with rationale, denial handling, and settings redirect.
Prevention
- Use
react-native-permissionsfor a unified API across platforms. - Check permission status before requesting.
- Handle all result states: GRANTED, DENIED, BLOCKED, UNAVAILABLE.
- Show rationale on denial, settings redirect on blocked.
- Add proper strings to Info.plist (iOS) and AndroidManifest.xml.
Common Mistakes with native camera permission
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations
These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro