Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

ios - How to accept/decline EKEvent invitation?

I would like to allow my users to accept/decline a meeting invitation within my app.

I think what I need is to update somehow the EKParticipantStatus but it looks like it isn't possible to update.

Apple Docs: Event Kit cannot add participants to an event nor change participant information

In this stackOverflow question someone suggested to bring the native EventKitUI, which I've tried like this:

  class CalendarViewController: UIViewController, EKEventViewDelegate {

        // .....

        let eventController = EKEventViewController()
        guard let eventWithIdentifier = MeetingsFetcher.eventStoreClass.event(withIdentifier: meeting.UUID) else {
            return nil
        }
        eventController.delegate = self
        eventController.event = eventWithIdentifier
        eventController.allowsEditing = true
        eventController.allowsCalendarPreview = true

        let navCon = UINavigationController(rootViewController: eventController)

        // customizing the toolbar where the accept/maybe/decline buttons appear
        navCon.toolbar.isTranslucent = false
        navCon.toolbar.tintColor = .blueGreen
        navCon.toolbar.backgroundColor = .coolWhite10

        // customizing the nav bar where the OK button appears
        navCon.navigationBar.callinAppearence()
        present(navCon, animated: true, completion: nil)

        // .....

        // view gets dismissed, so it does detects the action, but no effect
        func eventViewController(_ controller: EKEventViewController, didCompleteWith action: EKEventViewAction) {
              controller.dismiss(animated: true, completion: nil)
        }

The native UI shows pretty good but the buttons don't make any effect in the native calendar.

enter image description here

Am I missing something or it's just not possible? Why would they allow to interact with those buttons if it's not possible to save anything?

Thank you!

PD: I have these permissions in the info.plist:

  • Privacy - Calendars Usage Description
  • Privacy - Contacts Usage Description
  • Privacy - Reminders Usage Description

UPDATE:

Please note that EKEventEditViewController is not what I am looking for. This screen wouldn't allow me to accept or decline the event, it would only allow me to edit the details.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To allow the user to create, edit, or delete events, use the EKEventEditViewDelegate protocol.

let eventController = EKEventViewController()
guard let eventWithIdentifier = MeetingsFetcher.eventStoreClass.event(withIdentifier: meeting.UUID) else {
                return nil
            }
eventController.delegate = self
eventController.event = eventWithIdentifier
eventController.editViewDelegate = self
...

CalendarViewController class must conform to the EKEventEditViewDelegate protocol and must implement the eventEditViewController method to dismiss the modal view controller as shown below:

func eventEditViewController(_ controller: EKEventEditViewController, 
             didCompleteWith action: EKEventEditViewAction) {

    switch (action) {
        case EKEventEditViewActionCanceled:
        case EKEventEditViewActionSaved:
        ...
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...