을 지속하지. 나는 그들에게 이벤트를 저장할 수있다, 나는 나의 지방의 캘린더에서 그들을 볼 수있다. 그리고 삶은 좋다. 그러나 앱이 종료되고 백그라운드로 들어가면 캘린더가 사라지고 이벤트가 생성됩니다. 다른 소스에 Subscribed Calendars
소스를 캘린더에 저장해 봤지만 캘린더는 처음부터 저장하지 않습니다. Heres는 로컬 소스를 사용의 시도 중 하나 : 나는 또한이 방법을 시도스위프트 EKCalendar 나는 새 달력을 만들고 다음과 같은 기능을 저장할 수 있습니다
func createCalendarForUser() {
let sourcesInEventStore = self.eventStore.sources
//never saves calendar
let localSourceIndex = sourcesInEventStore.index {$0.sourceType == .local}
if let localSourceIndex = localSourceIndex {
let userCalendar = EKCalendar(for: .event, eventStore: self.eventStore)
userCalendar.title = "newCalendar"
userCalendar.source = sourcesInEventStore[localSourceIndex]
do {
try self.eventStore.saveCalendar(userCalendar, commit: true)
print("creating new calendar successful")
} catch {
print("creating new calendar failed : \(error)")
}
}
}
: 여기에 언급 한 바와 같이 여기 metioned로
func createCalendarForUser() {
let sourcesInEventStore = self.eventStore.sources
//doesnt work
let userCalendar = EKCalendar(for: .event, eventStore: self.eventStore)
userCalendar.title = "newCalendar"
userCalendar.source = sourcesInEventStore.filter{
(source: EKSource) -> Bool in
source.sourceType.rawValue == EKSourceType.local.rawValue
}.first!
do {
try self.eventStore.saveCalendar(userCalendar, commit: true)
print("creating new calendar succesful")
} catch {
print("creating new calendar failed : \(error)")
}
}
는 https://www.andrewcbancroft.com/2015/06/17/creating-calendars-with-event-kit-and-swift/
다른 사람이 문제를 건너 했습니까?
실제로 저는 캘린더 ID를 UserDefaults에 저장하지만 코드가 약간 남겨져 코드를 남겼습니다. 내가 말했듯이, 나는 그들에게 이벤트를 쓸 수 있기 때문에 그것들을 검색하는 것은 문제가되지 않는다. 문제는 앱을 죽인 다음 다시 열면 UserDefaults의 ID를 사용하는 경우에도 캘린더가 전혀 발견되지 않습니다. –
흠. tbh 필자는이 API에 대한 경험이 없지만'saveCalendar (, commit :) '오류를 포착하지 않으면 문제가 지속성이 아닌 검색이라는 것을 느낀다. 캘린더에 액세스 할 수있는 권한이 있는지 확인할 수 있습니다 ('EKEventStore.authorizationStatus (for :)')는'EKAuthorizationStatus.authorized'를 반환합니까? – MathewS
내가 만든 Apple 캘린더 앱에서 만든 캘린더와 내가 만든 모든 이벤트를 볼 수 있기 때문에 권한이 있습니다. 앱이 몇 초 동안 백그라운드에 앉아서 캘린더를 찾을 수 없기 때문에 지속성 문제를 안다. 앱을 다시 시작하기 전에 Apple 캘린더를 확인하고 캘린더와 모든 이벤트가 사라 졌는지 확인합니다. –