How to create and save EKCalendar on ios 6

后端 未结 7 1247
自闭症患者
自闭症患者 2020-12-05 03:42

I\'m having an issue where I create my EKCalendar and everything looks good but then when I go to list my calendars, it doesn\'t show up. I also go to check my calendar list

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 03:48

    The local store may not support events. This is reproducible if iCloud is enabled.

    This is the most reliable solution I could find, without hard-coding any assumptions:

        let calendar = EKCalendar(forEntityType: .Event, eventStore: eventStore)
    
        if eventStore.sources.count == 0 { // reproducible after Reset Content and Settings
            calendar.source = EKSource()
        }
        else {
            calendar.source = eventStore.defaultCalendarForNewEvents.source
        }
    
        eventStore.saveCalendar(calendar, commit: true)
    

提交回复
热议问题