Getting "User rejected permissions" when trying to open calendar

I keep getting a “User rejected permissions” when trying to create an event in the calendar. I’m running my app through the Expo Client. Is it possible even do this via the Expo client?

I have added these permissions app.json:

"android": {
   "permissions": ["READ_CALENDAR", "WRITE_CALENDAR"],
},

Code:

  Calendar.getCalendarsAsync()
    .then(event => {
      console.log(event);
    })
    .catch(error => {
      console.log(error);
    });

Fixed by asking for permission first. I think it would useful to add this to the documentation.

const { Location, Permissions } = Expo;
// permissions returns only for location permissions on iOS and under certain conditions, see Permissions.LOCATION
const { status, permissions } = await Permissions.askAsync(Permissions.CALENDAR);
if (status === 'granted') {
  return Calendar.getCalendarsAsync()
    .then(event => {
      console.log(event);
    })
    .catch(error => {
      console.log(error);
    });
} else {
  throw new Error('Calendar permission not granted');
}
1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.