Search code examples
iosswiftekeventkit

Can I open the the add event to calendar screen of the IOS calendar app with pre-filled data from my app?


I want to add a new event to the IOS calendar, I know this can be done easily using the EventKit. However I do not want to add the event directly, I want the calendar app to be launched with the "add event" screen pre-filled with data passed from my application, as shown in the attached screenshot, and the user can have the option to edit the event details, save the event or cancel it. I know I can launch the calendar app using the "calshow:" NSURL and UIApplication.shared.open function, however this only opens the day I pass it and not the "add event" screen I would like to open.

I've searched high and low for a way to do it but found nothing.

Any suggestions?

add event screen to be opened when calendar is launched


Solution

  • Yes, You can use EventKitUI framework for that.

    Use EKEventEditViewController.

    Presented modally, the event edit view controller provides a way for users to add new events, as well as edit or delete events from their calendar.

    Ref : Apple

    For pre-filled values use event property.

    // Create event 
       var store = EKEventStore()
       var event = EKEvent(eventStore: store)
       event.title = "Title"
            //event.startDate = startDate
            //event.endDate = currentEvent?.endDate
    
    
      let eventViewController: EKEventEditViewController = EKEventEditViewController()
      eventViewController.event = event
      eventViewController.eventStore = store
      eventViewController.editViewDelegate = self
    
    present(eventViewController, animated: true, completion: nil)