ios - 像Sunrise一样修改EventKit中的EKParticipants(与会者)

标签 ios objective-c exchange-server eventkit ekevent

我的目标是将一些受邀者添加到 EKEvent。我已经研究过类似的其他问题,例如 this one , 但所有人都说基本上不可能以编程方式将 EKParticipant 添加到 EKEvent 中。我确实看到 attendees 属性是只读的,但我看到其他服务,如 Sunrise在他们的移动应用程序中使用它。

我确信他们正在使用至少部分与 EventKit 集成的系统,因为他们从用户的 iCal 应用程序中提取日历。例如,从添加的 Exchange 帐户发送的邀请也显然是由 Exchange 服务发送的,而不是 Sunrise 自己的邀请(结果是直接将事件发布到 Exchange 或将其发布到 iCal)。

此限制的任何解决方法都会非常有帮助 - 也许可以调用 Exchange 上的端点来添加/删除受邀者? EventKit 内部的解决方法?只要它不是私有(private) Apple API,我就非常乐意尝试一下。

谢谢!

最佳答案

我想通了!

本质上,必须进入 EKAttendee 类,它继承自 EKParticipant。我通过使用 NSClassFromString() 方法创建该类的通用实例来做到这一点。

有了与会者后,您可以使用 setValue:ForKey: 函数设置属性。

最后,将您的 EKAttendee 实例编译成一个数组,并将其设置为 EKEventattendees 属性。

我在我的设备上使用 Exchange 帐户对此进行了测试,它非常有效 - 已发送邀请和所有内容!

下面的代码是我现在用来设置事件参与者的代码。我的示例是创建新事件,但对于现有事件,这可以非常简单地完成,方法是复制 EKEvent 上的 attendees 列表,然后修改它并重新设置它。

//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!");
}

关于ios - 像Sunrise一样修改EventKit中的EKParticipants(与会者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30627694/

相关文章:

php - 如何将 NSString 从 JSON 转换为 NSDictionary?

ios - 可选类型 UILabel 的值未展开。

objective-c - b/w addObject :dictionary and addObject:[dictionary copy] to an NSMutableArray? 有什么区别

iphone - 为什么 ViewController 类的单独实例会影响前一个实例?

javascript - 无法在 Safari 8.0.8 中检查 iOS 设备

iOS MDM 政策

objective-c - iOS 以编程方式拍照

powershell - 设置通讯组注释

powershell - 如何在VBScript中从PowerShell取回错误消息

c# - 如何使用 PowerShell 远程处理从 C# 向 Active Directory 用户添加图像?