我正试图从iCal获得本周所有事件的列表。我想看看有多少个事件,它们属于什么类别。如何通过编程来完成这一任务。Eventkit是正确的选择还是应该使用AppleScript?有关于Eventkit的教程吗?我找不到一个。
发布于 2015-04-02 12:14:23
我使用以下单例来访问EventStore
private let _SingletonSharedInstance = EventStore()
class EventStore {
let eventStore = EKEventStore ()
class var sharedInstance : EventStore {
return _SingletonSharedInstance
}
init() {
var sema = dispatch_semaphore_create(0)
var hasAccess = false
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: { (granted:Bool, error:NSError?) in hasAccess = granted; dispatch_semaphore_signal(sema) })
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)
if (!hasAccess) {
alert ("ACCESS", "ACCESS LONG")
let sharedWorkspace = NSWorkspace.sharedWorkspace()
sharedWorkspace.openFile("/Applications/System Preferences.app")
exit (0)
}
}
}注意:alert是我创建警报的私有方法之一。视需要更换它。
访问我使用的应用程序中的事件存储
let eventStore = EventStore.sharedInstance.eventStore
...
for et in eventStore.calendarsForEntityType(EKEntityTypeEvent) {
// check calendars
}关于那么的文档,事件存储是相当完整的,所以你很可能可以从这里开始。
https://stackoverflow.com/questions/29412517
复制相似问题