iOS Swift:从文件系统加载时区数据时出错

时间:2019-01-10 11:15:12

标签: ios swift ekevent ekeventstore

我正在尝试从去年到未来三年之间的EKEventStore中获取事件,但出现此错误:

  

从文件系统加载时区数据时出错。这是严重的   问题。不能保证日历数据的准确性。

如果我将上一年的日期从-1更改为0,则不会提示错误

这是代码:

 struct TaskService: TaskServiceProtocol {

        let store: EKEventStore

        init(withStore store: EKEventStore) {
            self.store = store
        }
        func tasks() -> [TaskItem] {
            let calendar = Calendar.current
            let today = Date()
            let startDate = calendar.date(byAdding: .year, value: -1, to: today)!
            let endDate = calendar.date(byAdding: .year, value: 3, to: today)!
            let eventsPred = store.predicateForEvents(withStart: startDate, end: endDate, calendars: nil)
            let events = store.events(matching: eventsPred) as? [TaskItem] ?? []
            return events
        }
    }

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        requestAccess()
    }

    func requestAccess() {
        let store = EKEventStore.init()
        store.requestAccess(to: .event) { (granted, error) in
            let service = TaskService(withStore: store)
            let events = service.tasks()
            print(events.count)
        }
    }
}

0 个答案:

没有答案