如何在ios日历中提取假期?

时间:2016-04-13 17:14:27

标签: ios objective-c swift

如何从ios日历中提取假期?

我希望能够从日历中读取事件并在我自己的日历程序中使用它们吗?

2 个答案:

答案 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)
}