Using new Calendar API


I’d like to add an event to a user’s calendar.

Looking at the API, it appears I need to call createEventAsync. But this requires a calendarId parameter. So am I supposed to call getCalendarsAsync first and then choose one of the IDs returned?

When I call getCalendarsAsync it returns an empty array. So now I’m stuck not having a calendarId to use for calling createEventAsync.

I just want to add an event to a user’s default calendar. How do I do this?



Hey @thenewt15 - thanks for the question. Yes, the workflow you mentioned is correct for now. However, you need to ask for permission to use the user’s calendars first. Unfortunately this got missed in the docs - will be fixed soon, but for now you need to call await Permissions.askAsync('calendar') before you can get any info back. Let me know if that doesn’t fix your problem.

As far as using the default calendar, it depends on which platform you’re using. On Android, you can iterate through the results of getCalendarsAsync until you find the one with isPrimary: true. On iOS, there’s a way to get the default calendar by passing in a null calendarId, but your post reminded me that I forgot to expose this through the JS (whoops). I’ll see about getting that into SDK 26, which should be out soon.

Hope this helps a little. We are still working out the kinks with this API, & really appreciate people the feedback from people like you!

1 Like


Being able to add an event to the default calendar (by passing null to createEventAsync) would be great.

After granting permissions, I was able to get back some results from getCalendarsAsync. On iOS it returns an array of objects. For the default calendar, the object looks like this (showing only some of the properties).

  id: "someLongHash",
  allowsModifications: true,
  source: {
    id: "someLongHash"
    name : "Default"
    type: "local"

I’ve already found the the id inside of the source object is not the one I want.

So I’m guessing the right way to add an event to the default calendar is as follow:

  1. Iterate through the returned calendars until you find one that has = "Default".
  2. Make sure this calendar has allowsModications === true.
  3. Take the id from the id key. Not the key. Pass the ID to createEventAsync.

Is this what you’d recommend?



Hi @thenewt15 - that sounds right to me. And yes, you will need to use the id property of the calendar object returned, not

We’ll try and streamline this process soon. Thanks for the feedback and for bearing with us!



We’re having a very similar issue. The first time the user grants calendar permissions the getCalendarsAsync function returns an empty array. This behavior continues anytime getCalendarsAsync is called during that sessions. However, once the user refreshes the app, the calendars array is properly returned.



A different question: is it possible to add and update attendees on a calendar event on iOS? I see Expo.Calendar.createAttendeeAsync is android-only, and I don’t see attendees in createEventAsync or updateEventAsync.

I am just evaluating, so I don’t have a project up and running yet.



Hmm, I’ve never seen that before @vivek99m :thinking:are you sure you’re awaiting permissions properly? Which OS and device model are you using?



Hi @dfrankow - unfortunately the docs are correct in that case. Apple does not allow third-party apps to modify calendar attendees on iOS, only view them. Sorry about that :slightly_frowning_face:



@esamelson Gotcha. Thanks for the reply!



I just deployed an AdHoc iOS build to my device. When testing on the simulator, adding events to the calendar worked fine. But on my device, it doesn’t work. No events shows up on my calendar. And I’m not getting back an eventID when I try to create an event (which is how I programmatically determine if it succeeded).

I have an ejected ExpoKit app. Adding calendar events works on the simulator when using exp start and then running from XCode. But it doesn’t work when I exp publish and then distribute a binary. Is there something I’m missing?


1 Like

closed #11

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