How to open Calendar app event's detail by its ID

Hey there,

I'd like to ask for guidance on how to open the Apple Calendar app's event programmatically. I can already list events, but I'm struggling to open the calendar detail view (upon user interaction).

I've tried many variants, such as using the x-apple-calevent URL scheme or calshow:\, etc., but none of them worked.

Here's the code I'm using:

if let eventIdentifier = event.eventIdentifier as String?, 
   let calendarId = event.calendarId as String? {
    if let url = URL(string: "x-apple-calevent://\(calendarId)/\(eventIdentifier)") {
        NSWorkspace.shared.open(url)
    }
}

Once the action is triggered, it tells me that:

There is no application set to open the URL 
x-apple-calevent://909114A0-6352-47DB-B70E-2770H7D5B6D3:7q50iih7fvbio3qipk5m7osjig@google.com

Thanks a bunch!

Tom

To open the Apple Calendar app's event detail view programmatically, you can use the EventKit framework. In my investigation observed there isn't a direct URL scheme to open a specific event in the Calendar app. Instead, you can open the Calendar app and focus on the date of the event.

let eventStore = EKEventStore()

eventStore.requestAccess(to: .event) { (granted, error) in
    if granted {
        let event = eventStore.event(withIdentifier: "your_event_identifier")
        if let event = event {
            DispatchQueue.main.async {
                let eventViewController = EKEventViewController()
                eventViewController.event = event
                eventViewController.allowsEditing = true
                eventViewController.allowsCalendarPreview = true
                if let viewController = UIApplication.shared.keyWindow?.rootViewController {
                    let navigationController = UINavigationController(rootViewController: eventViewController)
                    viewController.present(navigationController, animated: true, completion: nil)
                }
            }
        } else {
            print("not found")
        }
    } else {
        print("denied")
    }
}

Make sure you have the correct event identifier. This identifier is unique for each event and can be retrieved when you create or list events.

Remember to add the necessary keys to your app's Info.plist to request calendar access.

username- Sairam Agireeshetti

How to open Calendar app event's detail by its ID
 
 
Q