0
0
React Nativemobile~20 mins

Permissions handling in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Permissions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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;
}
AThe permission request returns 'denied', and the app can handle this state gracefully.
BThe app navigates to the home screen without any permission check.
CThe permission is automatically granted after denial without user action.
DThe app immediately crashes due to lack of permission.
Attempts:
2 left
💡 Hint
Think about how permission APIs usually respond when a user denies access.
🧠 Conceptual
intermediate
1: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?
A"denied"
B"granted"
C"blocked"
D"unavailable"
Attempts:
2 left
💡 Hint
This status means the user must manually enable permission in device settings.
lifecycle
advanced
2: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?
ANever check; assume permissions are granted.
BOnly once when the app is first installed.
COnly when the user clicks a button to request permission.
DEvery time the app component mounts or gains focus.
Attempts:
2 left
💡 Hint
Think about when the user might change permissions outside the app.
🔧 Debug
advanced
2: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;
  });
}, []);
AThe state variable is assigned directly instead of using the setter function.
BThe permission constant is incorrect for Android.
CThe useEffect hook is missing a dependency array.
DThe permission request API is asynchronous and must use async/await.
Attempts:
2 left
💡 Hint
How do you update React state properly?
navigation
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();
  }
}
AUse Linking.openURL('app-settings:') on both iOS and Android.
BUse Linking.openSettings() on Android and Linking.openURL('app-settings:') on iOS.
CUse Linking.openSettings() on both platforms.
DUse Linking.openURL('settings:') on iOS and Linking.openSettings() on Android.
Attempts:
2 left
💡 Hint
Different platforms require different URL schemes or methods.