修改EventKit中的EKParticipants(与会者),例如Sunrise [英] Modifying EKParticipants (attendees) in EventKit like Sunrise
问题描述
我的目标是将一些被邀请者添加到 EKEvent
。我已经研究过这样的其他问题,例如这一个 ,但是所有人都说,基本上不可能以编程方式将 EKParticipant
添加到 EKEvent
。我确实看到与会者
属性是只读的,但我看到其他服务,如日出在他们的移动应用中使用它。
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.
我'我确信他们正在使用一些至少部分与EventKit集成的系统,因为他们从用户的iCal应用程序中提取日历。例如,从添加的Exchange帐户发送的邀请也由Exchange服务明确发送,而不是Sunrise自己的邀请(将事件直接发布到Exchange或将其发布到iCal)。
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).
此限制的任何解决方法都非常有用 - 可能是Exchange上可以调用添加/删除被邀请者的端点? EventKit内部的解决方法?只要它不是私有的Apple API,我就会非常乐意尝试它。
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.
谢谢!
推荐答案
我想通了!
基本上,必须进入 EKAttendee
class,继承自 EKParticipant
。我这样做是通过使用 NSClassFromString()
方法创建该类的通用实例。
Essentially, one must go into the EKAttendee
class, which inherits from EKParticipant
. I did this by creating a generic instance of that class using the NSClassFromString()
method.
有了与会者后,您可以使用 setValue:ForKey:
函数设置属性。
Once you have an attendee, you can set the properties using the setValue:ForKey:
function.
最后,将 EKAttendee
实例编译成数组,并将其设置为 EKEvent
的与会者
属性。
Lastly, compile your EKAttendee
instances into an array, and set that to the EKEvent
's attendees
property.
我在设备上使用Exchange帐户对此进行了测试,并且像魅力一样工作 - 邀请发送和一切!
I tested this with an Exchange account on my device, and it worked like a charm - invite sent and everything!
下面的代码是我现在用来设置事件参与者的代码。我的例子是创建新事件,但是通过在 EKEvent上复制
,然后修改并重新设置它。与会者
列表,可以非常简单地对现有事件进行此操作
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 the EKEvent
, then modifying that and re-setting it.
//Create generic event info
EKEvent *event = [EKEvent eventWithEventStore:database];
event.title = @"TEST EVENT";
event.location = @"Test location";
event.notes = @"Example notes";
event.startDate = [NSDate date];
event.endDate = [[NSDate date] dateByAddingTimeInterval:(60 * 60)];
event.calendar = exchange;
//Do our super clever hack
NSMutableArray *attendees = [NSMutableArray new];
for (int i = 0; i < 5; i++) {
//Initialize a EKAttendee object, which is not accessible and inherits from EKParticipant
Class className = NSClassFromString(@"EKAttendee");
id attendee = [className new];
//Set the properties of this attendee using setValue:forKey:
[attendee setValue:@"Invitee" forKey:@"firstName"];
[attendee setValue:[NSString stringWithFormat:@"#%i", i + 1] forKey:@"lastName"];
[attendee setValue:@"test@email.com" forKey:@"emailAddress"];
//Add this attendee to a list so we can assign it to the event
[attendees addObject:attendee];
}
//Finally, add the invitees to the event
[event setValue:attendees forKey:@"attendees"];
//Save the event!
NSError *error = nil;
[database saveEvent:event span:EKSpanThisEvent error:&error];
if (error) {
NSLog(@"Save failed with error: %@", error);
} else {
NSLog(@"Success!");
}
这篇关于修改EventKit中的EKParticipants(与会者),例如Sunrise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!