Challenge - 5 Problems
Permissions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when permission is denied in React Native?
Consider a React Native app that requests camera permission using
react-native-permissions. What is the expected behavior if the user denies the permission request?React Native
import {check, request, PERMISSIONS, RESULTS} from 'react-native-permissions'; async function requestCameraPermission() { const result = await request(PERMISSIONS.IOS.CAMERA); return result; }
Attempts:
2 left
💡 Hint
Think about how permission APIs usually respond when a user denies access.
✗ Incorrect
When a user denies permission, the API returns a 'denied' status. The app should detect this and handle it, such as showing a message or disabling features that require the permission.
🧠 Conceptual
intermediate1:30remaining
Which permission status means the user permanently denied access?
In React Native permissions handling, which status indicates the user has permanently denied permission and the app cannot request it again without user action in settings?
Attempts:
2 left
💡 Hint
This status means the user must manually enable permission in device settings.
✗ Incorrect
The "blocked" status means the user permanently denied permission, so the app cannot prompt again and must direct the user to settings.
❓ lifecycle
advanced2:00remaining
When should you check permissions in a React Native app lifecycle?
You want to ensure your React Native app always has the latest permission status for location access. When is the best time to check permissions to update your UI accordingly?
Attempts:
2 left
💡 Hint
Think about when the user might change permissions outside the app.
✗ Incorrect
Permissions can change anytime, including when the app is backgrounded. Checking on component mount or focus ensures the app UI reflects current permission status.
🔧 Debug
advanced2:30remaining
Why does this permission request code fail to update UI?
Given this React Native code snippet, why does the UI not update after requesting permission?
const [cameraStatus, setCameraStatus] = useState('unknown');
useEffect(() => {
request(PERMISSIONS.ANDROID.CAMERA).then(status => {
cameraStatus = status;
});
}, []);Attempts:
2 left
💡 Hint
How do you update React state properly?
✗ Incorrect
Directly assigning to the state variable does not update React state or trigger a re-render. The setter function must be used.
expert
3:00remaining
How to navigate user to app settings after permission is blocked?
In React Native, if a permission is 'blocked', the app should guide the user to the app settings page to enable it manually. Which code snippet correctly opens the app settings screen?
React Native
import {Linking, Platform} from 'react-native'; function openSettings() { if (Platform.OS === 'ios') { Linking.openURL('app-settings:'); } else { Linking.openSettings(); } }
Attempts:
2 left
💡 Hint
Different platforms require different URL schemes or methods.
✗ Incorrect
On iOS, the URL scheme 'app-settings:' opens settings. On Android, Linking.openSettings() is the correct method.