Expo - creating calendar is missing source

1.2k views Asked by At

When attempting to create a calendar on iOS I'm getting:

Calendar 'My Calendar' could not be saved: Error Domain=EKErrorDomain 
Code=14 "Calendar has no source" UserInfo=
{NSLocalizedDescription=Calendar has no source}

My calendar config looks like:

 {
   "allowsModications": true,
   "color": "yellow",
   "entityType": "event",
   "source": {
     "id": "220e5c20-eee3-406a-b1e0-cbd59b06ce66",
     "name": "workout-scheduler",
     "type": "local",
   },
   "sourceId": "220e5c20-eee3-406a-b1e0-cbd59b06ce66",
   "title": "My Calendar",
   "type": "local",
 }

My project is running with

"expo": "^34.0.0",
"expo-calendar": "~6.0.0"
1

There are 1 answers

1
Daniel On

So for the curious or those who might find themselves having this kind of issue you should know that while Android allows defining the source with pretty much any value iOS won't.

So what I did is, upon calendar creation I first fetch the existing calendars and pick the first which has a source of type caldav - This standard is used by iCloud so it will be present on the device. Once I have that calendar I take from him the source ID and set it as the source ID for my app calendar.

let iOsCalendarConfig = {
  title: "Workout Events",
  color: '#4B968A',
  entityType: Calendar.EntityTypes.EVENT,
}

const getEventsCalendars = () => {
  return Calendar.getCalendarsAsync(Calendar.EntityTypes.EVENT)
}

export const createCalendar = async (gymConfig) => {
  let osConfig;
  switch (Platform.OS) {
  case "ios":
    const calendars = await getEventsCalendars()
    const caldavCalendar = calendars.find(calendar => calendar.source.type == "caldav")
    osConfig = iOsCalendarConfig;
    // Sources can't be made up on iOS. We find the first one of type caldav (most common internet standard)
    osConfig.sourceId = caldavCalendar.source.id
    break;
  case "android":
    ...
    break;
  default: 

 }

 return Calendar.createCalendarAsync(osConfig)
}

Even though this works I am conscious that for example I can't create a local calendar on iOS as I did on Android; which makes me thing that there is more to this calendars subject that needs to be dug.