swiftuideep-linking

How to open a Reminders App reminder item using


I wrote a simpel app to integrate and work with Apple Reminders (CRUD).

The thing I struggle with is opening a Reminders item from my app using the calendarItemIdentifier. I get the identifier but I can’t build a valid URL or call Apple Reminders properly.

@Environment (\.openURL) private var openUrl

//...

let url = URL(string: "x-apple-reminder://\(reminder.calendarItemIdentifier)")
openUrl(url!)

I get the following error message:

Failed to open URL x-apple-reminder://FB2D0D45-23E9-4851-A86E-636064BA6A39: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=277, _LSFunction=-[_LSDOpenClient openURL:fileHandle:options:completionHandler:]}

Solution

  • The error you are encountering

    (Error Domain=NSOSStatusErrorDomain Code=-10814)

    typically means that the system cannot find an application to handle the custom URL scheme (x-apple-reminder://). Unfortunately, Apple Reminders does not support opening specific reminders directly via a URL scheme, which is why this approrach is not working.

    I Made a simple solution for you using EventKit. Please note that this is mostly copied code from 2 years ago, so there will probably be something deprecated.

    Here's a way to list reminders, which you might have already implemented:

    First of all you need to import the necessary frameworkss:

    import EventKit
    

    Then you need to request Access:

    let eventStore = EKEventStore()
    
    eventStore.requestAccess(to: .reminder) { (granted, error) in
        if granted {
            // Access granted
        } else {
            // Show some kind of alert or something, because you got denied.
        }
    }
    

    Fetch Reminders:

    let predicate = eventStore.predicateForReminders(in: nil)
    eventStore.fetchReminders(matching: predicate) { reminders in
        for reminder in reminders ?? [] {
            print("Reminder: \(reminder.title ?? "No title")")
        }
    }
    

    For now, here's what you can do if you need to open the Apple Reminders app itself:

    let url = URL(string: "x-apple-reminder://")!
    openUrl(url)
    

    This will open the Reminders app, but not a specific reminder. I would try to wrap everything into a custom class or sth. so permission is asked on init. etc.. this should also make it easier to handle edge cases.