Local EKCalendar saved with not errors, disappears

。_饼干妹妹 提交于 2019-12-13 04:49:45

问题


I'm trying to create a calendar with EKSourceTypeLocal source. Iterate over the self.eventStore.sources, find the one with sourceType == .Local and attempt to create a new calendar with it.

self.calendar = EKCalendar(forEntityType: EKEntityType.Event, eventStore: self.eventStore)
self.calendar?.title = "My Awesome Calendar"
self.calendar?.source = src // src.sourceType == .Local
print("Created \(self.calendar!)")
do {
     try self.eventStore.saveCalendar(self.calendar!, commit: true)
} catch let err as NSError {
      print("Whoops: \(err)")
}

That executes without a problem, and allows me to add some events to that calendar as well. However, when I switch to the native Calendar app, this new one is no there, if I query self.eventStore.calendarsForEntityType(EKEntityType.Event) after the above has completed, it's not there either, and if I restart the app, the calendar I created and all its events are nowhere to be found. What's happening?


回答1:


If you have calendars from other sources active on your device, calendars of type EKSourceTypeLocal will not be visible in the Apple Calendars app.

Additionally, the event store will not show the local calendar when other calendar sources are active.

If you de-activate the other calendars, you should be able to see the saved local calendar in both the Calendars app and the event store.

I’m assuming your app has the necessary permissions obtained using requestAccessToEntityType:completion:.



来源:https://stackoverflow.com/questions/33640657/local-ekcalendar-saved-with-not-errors-disappears

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!