简体   繁体   English

创建一个提醒列表,该列表可以将您的提醒保存在通过我的应用创建的提醒应用中

[英]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. 因此,我有一个可以在其中创建提醒并将其添加到iPhone上的Reminder App的应用程序。 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. 班上还有其他凝灰岩,例如viewedload和类似的东西。

If you need more code or have any questions ask me! 如果您需要更多代码或有任何疑问,请问我!

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. 该方法假定存在一个属性eventStore其中EKEventStore实例。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM