12

在我的 iOS 应用程序中,我曾经使用以下方法访问日历:

EKCalendar* cal = [eventStore calendarWithIdentifier:[calendarIDs objectAtIndex:i]];

通过以下方式向用户询问权限:

eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,NSError* error){}

现在这在 iOS 7 上运行良好,但在 iOS 8 上,每次调用方法 calendarWithIdentfier 时我都会收到以下错误:

Error getting shared calendar invitations for entity types 3 from daemon: 
Error Domain=EKCADErrorDomain Code=1013 
"The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"

我可以毫无问题地写\读日历,但我不明白为什么会引发这个异常。我已经尝试过这里提出的一些方法,但在这种情况下似乎都没有。

4

2 回答 2

10

我也被同样愚蠢的事情难住了。

我只是遍历了一组日历并根据标识符进行匹配。它并不优雅,但它可以工作,普通用户的日历可能少于 10 个,所以......哦,好吧......

这是我的快速解决方法

func createEvent(){
    var event = EKEvent(eventStore: self.eventStore)
    var calendar : EKCalendar!
    let calendars : [EKCalendar] = self.eventStore.calendarsForEntityType(EKEntityTypeEvent) as [EKCalendar]

    for aCal in calendars
    {
        if(aCal.calendarIdentifier == self.calendarIdentifier)
        {
            calendar = aCal
            break
        }
    } ...continue to do stuff to events....

}
于 2014-09-22T15:50:39.047 回答
2

斯威夫特 4.2

代替

let matchedCal = eventStore
    .calendar(withIdentifier: calendarIdentifier)

您可以使用:

let matchedCal = eventStore
    .calendars(for: .event)
    .first(where: { $0.calendarIdentifier == calendarIdentifier })
于 2018-09-30T01:46:46.467 回答