Select Page

Hey, devs. This article is about something that can be very helpful while developing an application. I will talk about permissions in an expo app. When you develop an app, you might need to use the camera of the mobile, get the permission because we need to send notification or more. How can we achieve this? Expo allows us to use an API for this! Let’s see the steps.

Let’s import the permission from expo:

import { Permissions } from 'expo';

We are going to use it in a function which you can then call it later inside the return of your class or main function.

The function we create has to be asynchronous. In this example we are putting the value permission equal to Permissions.getAsync. Inside of it we are asking for the permission for the location.

 async obtainNotificationPermission() {
        let permission = await 
Permissions.getAsync(Permissions.LOCATION);
        if (permission.status !== 'granted') {
           console.log("You have permission")
        }
        return permission;
    }

The “permission” value will be an object. It contains:

  • status, which can be equal to: granteddeniedundetermined
  • granted, a boolean
  • canAskAgain, a boolean, its value depends on what the user chooses. There is the option to not allow an app to ask again for permission.

This was a small example where you can ask for the user’s location, but you can ask for many more things: “CAMERA”, “CONTACTS”, “CALENDAR” and more.

This is the end of the article about permissions in an expo app. In each article we are discovering how much expo can help us developing an app and making it less stressful. Keep following me and my instagram to know more about react native!

Check other posts