CodeBlanks Logo Icon CodeBlanks

Notification permission

Learn to ask for notification permission.

Notification permission

Notification permission is the approval required for the app to send push notifications. It is requested with Permissions.askAsync(Permissions.NOTIFICATIONS). On iOS this permission must be explicitly asked for or notifications cannot be sent; on Android it may be on by default but asking is still a good habit.

Notifications are a powerful tool to bring users back; but misused they make the user uninstall the app. That is why the permission should be asked at a moment that truly adds value. For example asking 'Turn on notifications' after the user sets a reminder is more effective than asking at launch. If denied the user can re-enable from settings; so showing a 'Turn on notifications from settings' message is good.

Practice Write requestNotificationPermission

Write a requestNotificationPermission function. Make it async. Call Permissions.askAsync(Permissions.NOTIFICATIONS) with await; return status.

Starter code

App.js
// Write the requestNotificationPermission function
// Ask NOTIFICATIONS permission with Permissions.askAsync; give back the status

Sample solution

App.js
async function requestNotificationPermission() {
  const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  return status;
}

The first request

On iOS a system dialog appears the first time notification permission is requested. The user picks 'Allow' or 'Deny'. If denied, asking again does not show the dialog; the user must enable from settings.

On Android behavior depends on the API level. On Android 13+ (Tiramisu) notification permission must be explicitly asked for; it behaves like iOS. On older versions notifications are on by default; askAsync still works but does not show a dialog. That is why it is a good habit to always call askAsync so the app behaves consistently on both platforms. You should check the result with status and route the flow accordingly.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which permission is needed for push notifications?

App.js
Permissions.askAsync(Permissions.NOTIFICATIONS);
  • Camera permission
  • Notification permission Correct answer
  • Location permission
  • Microphone permission

Explanation: Push notifications need notification permission.

2 NOTIFICATIONS permission

Question
await Permissions.askAsync(Permissions.____);
Answer
await Permissions.askAsync(Permissions.NOTIFICATIONS);

Explanation: Permissions.NOTIFICATIONS is the notification permission.

3 Match each concept to its role

Term Meaning
NOTIFICATIONS Notification permission
iOS Asks explicitly
Android 13+ 13+ version
Denied Route to settings

All lessons in Intermediate