简体   繁体   English

创建没有警报的 EKEvent

[英]Create EKEvent with no alarm

I'm creating an EKEvent attached to a custom calendar.我正在创建一个附加到自定义日历的 EKEvent。 Whenever I create the EKEvent an alarm is set for the time of the event, however, I would like this event to not have an alarm on creation.每当我创建 EKEvent 时,都会为事件的时间设置警报,但是,我希望此事件在创建时没有警报。

I've tried setting the event's alarms property to...我试过将事件的警报属性设置为...

event.alarms = nil

as well as...也...

event.alarms = []

I've also tried setting the alarm to a distant future data, but this just adds another alarm to the event...我也尝试将警报设置为遥远的未来数据,但这只是为事件添加了另一个警报......

event.alarms = [Date.distantFuture]

I've done all this before saving the event, but it has given me no results, the alarm fires no matter what I do.我在保存事件之前已经完成了所有这些,但它没有给我任何结果,无论我做什么都会触发警报。 :( :(

Here is the code I'm using to create the calendar:这是我用来创建日历的代码:

let calendar = EKCalendar(for: .event, eventStore: store)
var source = store.sources.filter{ $0.sourceType == .calDAV && $0.title == "iCloud" }.first
if source == nil {
    source = store.sources.filter{ $0.sourceType == .local }.first
}
calendar!.title = "Some Title"
calendar!.cgColor = ColorKey.orange.color().cgColor
calendar!.source = source!

do {
    try store.saveCalendar(calendar!, commit: true)
} catch {
    //error handling here...
}

And this is the code that I'm using to create the event:这是我用来创建事件的代码:

let event = EKEvent(eventStore: store)
event.title = "Some title"
event.notes = "Some notes"
event.startDate = dateToFire
event.endDate = dateToFire.addingTimeInterval(TimeInSeconds.hour.rawValue)
event.isAllDay = false
event.calendar = calendar
do {
    try store.save(event, span: EKSpan.futureEvents)
} catch {
    //error handling here...
}

Is this a bug on the OS or am I missing something?这是操作系统上的错误还是我遗漏了什么? Thanks!谢谢!

您是否尝试过 EkCalendarItem 类中的 removealaram 方法?

There are default alert settings in Apple's Calendar app. Apple 的日历应用程序中有默认警报设置。 Launch Calendar, then go to Preferences, Alerts.启动日历,然后转到首选项、警报。 There are three settings there (Events, All Day Events, Birthdays).那里有三种设置(事件、全天事件、生日)。 Set them to "None."将它们设置为“无”。 (I'm using macOS 10.14, Calendar 11.0.) (我使用的是 macOS 10.14,日历 11.0。)

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

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