PMT
PMT

Reputation: 1092

How can I display the details of a EKEvent invitation within my app using EKEventViewController?

BRIEF SUMMARY

I want the users of my app to be able to accept/decline an event invitation of their calendar. For this I am trying to bring up the event using EventKitUI components and allow the user to update the event without leaving my app. The problem is that it crashes whenever I assign an EKEvent to the EKEventViewController.

DETAILED EXPLANATION

WHAT I WANT:

To display a similar view like the one in the native iOS Calendar, so it should look something like this:

enter image description here

WHAT I HAVE:

import UIKit
import EventKitUI

class CalendarViewController: UIViewController, EKEventViewDelegate, EKEventEditViewDelegate {

   var meetingID = "id"

   override func viewDidLoad() {
       super.viewDidLoad()
       //self.showEditEvent(meeting: meetingID)
       self.showInvite(meeting: meetingID)
   }

   func showInvite(meeting: Meeting){
        let evc = EKEventViewController()
        var event = EKEvent(eventStore: MeetingsFetcher.eventStoreClass)
        event = MeetingsFetcher.eventStoreClass.event(withIdentifier: meetingID)!
        evc.delegate = self 
        evc.event = event
        evc.allowsEditing = true
        evc.allowsCalendarPreview = true
        self.screen.present(evc, animated: true, completion: nil)
    }

    func eventViewController(_ controller: EKEventViewController, didCompleteWith action: EKEventViewAction) {
        controller.dismiss(animated: true, completion: nil)
    }
}

THE BIG PROBLEM: Whenever I assign the EKEvent to the evc.event it crashes because of privacy violation issues. Note that I do have permission to access the Calendar.

CRASHING DUE TO PRIVACY VIOLATION

evc.event = event

enter image description here

SIDE NOTES

It does work though to open the edit view of a meeting using EKEventEditViewController(), which proves that.

So this code works, but it's not the view that I was looking for:

    func showEditEvent(meeting: Meeting){
        let evc = EKEventEditViewController()
        evc.eventStore = MeetingsFetcher.eventStoreClass
        var event = EKEvent(eventStore: MeetingsFetcher.eventStoreClass)
        event = MeetingsFetcher.eventStoreClass.event(withIdentifier: meeting.UUID!)!
        evc.event = event
        evc.editViewDelegate = self
        self.screen.present(evc, animated: true, completion: nil)
    }

    func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
        controller.dismiss(animated: true, completion: nil)
    }

enter image description here

Upvotes: 4

Views: 1164

Answers (1)

PMT
PMT

Reputation: 1092

I finally solved it. It looks like apart from Calendar permission I need also to add into the info.plist Contacts permission.

Privacy - Contacts Usage Description

enter image description here

Upvotes: 6

Related Questions