简体   繁体   中英

How pass params to iCalendar from iOS Swift

We have an iPhone App which lets people configure events. People can select the date of the event, but not the hour. To do this, We have connected it to iCalendar. At the present, when we are on the event page.. we just press the iCalendar icon and automatically iCalendar opens on the same date of the calendar... and we have to select the hour + put the name of the event. So we are duplicating (putting twice) the name of the event ... one in our app, the other one in Icalendar.

Can i make the intengration which iCalendar in such a way so that when one presses the Icalendar button... It opens I calendar on the given date.. and then when I select the hour... the name of the event is also placed?

What would be the best way to configure this so that we do not have to put the event information twice. Thank you fopr letting me know.

First of all need to import EventKitUI like :

import EventKitUI

And add delegate : EKEventEditViewDelegate

And add following code to open new event screen with passed data as :

let eventStore = EKEventStore()
    eventStore.requestAccess(to: .event, completion: {(_ granted: Bool, _ error: Error?) -> Void in
        if granted {
            let event = EKEvent(eventStore: eventStore)
            event.title = "My Event Test 1"
            //event.location  = location;
            event.startDate = Date()
            event.endDate = event.startDate.addingTimeInterval(60 * 30)
            //event.notes     = notes;
            let controller = EKEventEditViewController()
            controller.eventStore = eventStore
            controller.event = event
            controller.editViewDelegate = self
            self.present(controller, animated: true, completion: { _ in })
        }
    })

And handle response according to user action as :

func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
switch (action) {
case .canceled:
    // User tapped "cancel"
    break;
case .saved:
    // User tapped "save"
    break;
case .deleted:
    // User tapped "delete"
    break;
}
self.dismiss(animated: true, completion: nil)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM