tezvyn:

Requesting runtime permissions on iOS and Android

AI-drafted, machine-checkedSource: interviewbeginner
WHAT IT TESTS

Permission lifecycle awareness.

OUTLINE

declare permissions in Info.plist and AndroidManifest, then check status and request at runtime just before use, handling granted, denied, and blocked.

WHAT THIS TESTS Whether you understand that declaring a permission is necessary but not sufficient, and that you must request and handle it at runtime with the user able to refuse.

A GOOD ANSWER COVERS First, the static declaration: on iOS you add the permission's usage-description key to Info.plist, for example NSCameraUsageDescription with a human-readable reason, or the app is rejected and crashes on access. On Android you add the corresponding uses-permission entries to AndroidManifest. Second, the runtime flow: dangerous permissions are not granted by installation, so at runtime, ideally just before you need the feature and with context for why, you check the current status and, if it is undetermined, call request, which shows the OS prompt. You must handle the result states: granted, denied, blocked or never-ask-again where the only path is the system Settings, and on iOS limited variants for photos. A unified library like react-native-permissions abstracts the platform differences and exposes check and request with consistent statuses.

COMMON WRONG ANSWERS Assuming the manifest or Info.plist entry alone grants access. Requesting all permissions on app startup, which users reject in bulk. Ignoring the blocked state where re-requesting does nothing and you must deep-link to Settings. Forgetting iOS requires the usage-description string or the app crashes. Not checking the status first and re-prompting unnecessarily.

LIKELY FOLLOW-UPS What is the difference between denied and blocked, how do you deep-link to app settings, how do iOS provisional or limited permissions work, and why request just-in-time rather than upfront.

ONE CONCRETE EXAMPLE For camera access you add NSCameraUsageDescription on iOS and CAMERA in AndroidManifest. When the user taps Scan, you call check(CAMERA); if undetermined you call request(CAMERA) and proceed only on granted; if blocked you show an explanation with a button that opens Settings via Linking.openSettings, since the OS will not prompt again.

Read the original → github.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.