如何从ios
日历中提取假期?
我希望能够从日历中读取事件并在我自己的日历程序中使用它们吗?
答案 0 :(得分:2)
试试这个
action-loc-key
答案 1 :(得分:1)
Swift3.0版
获取用户权限
func requestAccessToCalendar() {
eventStore.requestAccess(to: EKEntityType.event, completion: {
(accessGranted: Bool, error: Error?) in
if accessGranted == true {
DispatchQueue.main.async(execute: {
getALLEvents
})
} else {
}
})
}
func getALLEvents(){
let caledar = NSCalendar.current
let oneDayAgoComponents = NSDateComponents.init()
oneDayAgoComponents.day = -1
let oneDayAgo = caledar.date(byAdding: oneDayAgoComponents as DateComponents, to: Date(), wrappingComponents: true)
let oneYearFromNowComponents = NSDateComponents.init()
oneYearFromNowComponents.year = 1
let oneYearFromNow = caledar.date(byAdding: oneYearFromNowComponents as DateComponents, to: Date(), wrappingComponents: true)
let store = EKEventStore.init()
let predicate = store.predicateForEvents(withStart: oneDayAgo!, end: oneYearFromNow!, calendars: nil)
let event = store.events(matching: predicate)
}