My goal is to add some invitees to an EKEvent
. I've looked into other questions like this, such as this one, but all say that it is essentially impossible to add EKParticipant
s to an EKEvent
programmatically. I do see that the attendees
property is read-only, but I see other services like Sunrise using it in their mobile app.
I'm confident that they're using some system that at least partially integrates with EventKit because they're pulling in calendars from the user's iCal app. Invites sent from an added Exchange account, for example, are also clearly sent by the Exchange service as opposed to Sunrise's own invite (a result of either posting the event straight to Exchange or to posting it to iCal).
Any workaround this restriction would be very helpful - maybe an endpoint on Exchange that can be called to add/remove invitees? A workaround inside of EventKit? As long as it's not a private Apple API, I'd be more than happy to try it out.
Thanks!
I figured it out!
Essentially, one must go into the
EKAttendee
class, which inherits fromEKParticipant
. I did this by creating a generic instance of that class using theNSClassFromString()
method.Once you have an attendee, you can set the properties using the
setValue:ForKey:
function.Lastly, compile your
EKAttendee
instances into an array, and set that to theEKEvent
'sattendees
property.I tested this with an Exchange account on my device, and it worked like a charm - invite sent and everything!
The code below is what I'm now using to set the attendees of events. My example is for creating new events, but this can be done very simply for existing events by making a copy of the
attendees
list on theEKEvent
, then modifying that and re-setting it.Swift version of rebello95's solution. I can confirm it works like a charm! I played around with the
firstName
andlastName
properties but they do not seem to matter at all, so I left them out of my example. Only theemailAddress
matters, which is matched against your contact list to display a full name in for example the native calendar app.