iosswifteventkitekeventstoreekreminder

Create a Reminder List which can hold your reminders in the Reminders App that you create from my App


So I have an app where a reminder is created and added to the Reminder App on your iPhone. But in the Reminders App they have different List or categories. I want to create my own category for my app. And then I want to add reminders to that category.

So a snippet of my code is basically a button which then adds a reminder to a Random List(I think). But I want the reminder to be sent to a specific list(In the reminders app) that the app(my app) needs to create. And if the list is already created I need to use that list.

var eventStore = EKEventStore()
@IBAction func ActSetReminder(_ sender: Any) {
    let reminder = EKReminder(eventStore: self.eventStore)
    reminder.calendar = eventStore.defaultCalendarForNewReminders()    
    reminder.title = "the title doesn't matter to you"
    reminder.isCompleted = false


}

This is a super basic version of that method it does other stuff that aren't important for this problem. there are other tuff in the class like the viewedload and that stuff.

If you need more code or have any questions ask me!


Solution

  • In terms of the Calendar framework a Reminder Category is just a calendar.

    You can use this method, it checks if a (reminder) calendar for the bundle name exists. If it does return it, if not create one.

    The method assumes that there is a property eventStore holding the EKEventStore instance.

    func reminderCategory() throws -> EKCalendar {
        let calendars = eventStore.calendars(for: .reminder)
        let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String
        if let bundleCalendar = calendars.first(where: {$0.title == bundleName}) { return bundleCalendar }
    
        let calendar = EKCalendar(for: .reminder, eventStore: eventStore)
        calendar.title = bundleName
        calendar.source = eventStore.defaultCalendarForNewReminders()?.source
        try eventStore.saveCalendar(calendar, commit: true)
        return calendar
    }