Search code examples
iosobjective-cswifteventkitcaldav

CalDAV handling in Swift or Objective C


I'm trying to manipulate CalDAV events with EventKit or a third-party library. I have a CalDAV server hosted in my local network and I added some extra property parameters in the RESOURCES property of a VEVENT, it looks like:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
CREATED:20160108T144516Z
UID:9ED5366B-E3BD-4C32-BA67-4B9A1F5D39F7
DTEND:20160224T093000
TRANSP:OPAQUE
RESOURCES;X-ORE-IPP=%14119%;X-ORE-RES=%3%;X-ORE-STATUT=%103%;X-ORE-TYPE=
 %3%:
SUMMARY:summary test
DTSTART:20160224T090000
DTSTAMP:20160224T075721Z
LAST-MODIFIED:20160224T075721Z
SEQUENCE:0
DESCRIPTION:EII 25 27 lioei
 anto)
END:VEVENT
END:VCALENDAR

With EventKit we can manipulate some properties of the events but can how can we access the custom property parameters??


Solution

  • The API provided by the current EventKit is very limited and does not give you access to custom properties or custom property parameters. (It should however preserve the custom parameters - though RESOURCES may have special behaviour).

    In short: What you want is not possible with EventKit. You'll either need to implement CalDAV on your own or use a 3rd party library - CalConnect maintains a list.

    P.S.:

    Also your (ab)use of RESOURCES doesn't look quite right to me. First - it doesn't seem to have a value. That would probably confuse clients (they might just drop it - because, well, it doesn't specify any resources.

    Then RESOURCES is a pretty plain but multivalue property, e.g. from the RFC:

    RESOURCES:EASEL,PROJECTOR,VCR
    

    Your usage seems to suggest that your custom property parameters belong to a single resource (status etc). In iCalendar such scheduling is not usually done with the RESOURCES property but with the ATTENDEE property and a CUTYPE RESOURCE, like:

    ATTENDEE;CUTYPE=ROOM;STATUS=ACCEPTED:ore://localhost/rooms/28372
    ATTENDEE;CUTYPE=RESOURCE:STATUS=TENTATIVE:ore://localhost/beamers/8347
    

    I don't know what your actual 'ORE' use case is. If it is compatible with CalDAV (which I guess should be desirable), you might use ATTENDEE. If NOT it is probably better to use a custom property instead of custom property parameters, like that:

    X-ORE-RESOURCE;STATUS=ACCEPTED:ore://localhost/rooms/28372
    

    Note that you might want to use standard property parameters on that custom property (e.g. STATUS instead of X-ORE-STATUS).

    P.S.2: Your VCALENDAR uses floating time. That is technically valid but very few clients support that. Clients usually use floating dates for all-day events but UTC or TZ times for events with a time. They can probably read it, but will attach their local timezone if they edit the event. And by that make the event non-floating. Not sure whether that matters to you, but quite likely it is a good idea to attach a TZID.

    P.S.3: Your VCALENDAR lacks a PRODID.