SOLVED: Used await and a variable to store the promise.
I am trying to insert an event into the default calendar on an android device using react-native and expo sdk. Previously, one could create an event using the createEventAsync()
method with the 1st argument as Calendar.DEFAULT but that is no longer supported. I can use the getCalendarsAsync()
method to get all calenders but the object I am getting back is making no sense. Some code:
async addReservationToCalendar(date) {
await this.obtainCalendarPermission();
console.log(Calendar.getCalendarsAsync());
}
Someone had suggested that I could iterate through the responses to find a calendar with the isPrimary attribute set to true but I don't see how I achieve this. I have already gotten the permission and I am receiving the following promise as a response.
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
.
What do I need to do to set a calendar event on an android device using the expo Calendar API ?
Because that's a promise, you need to do like this
Calendar.getCalendarsAsync().then(calendars => console.log(calendars))