gpt4 book ai didi

ios - 如何在日历中设置默认提醒?

转载 作者:可可西里 更新时间:2023-11-01 00:01:25 24 4
gpt4 key购买 nike

尝试将偶数添加到我用户的日历中,但不确定如何设置默认提醒。到目前为止,我所拥有的是:

func createEvent(item: Item) {
let eventStore = EKEventStore()

eventStore.requestAccessToEntityType(EKEntityType.Event, completion: { (granted, error) in
if granted && error == nil {
let event = EKEvent(eventStore: eventStore)
event.title = item.name
event.startDate = item.StartDate
event.endDate = item.endDate
event.notes = item.description
event.calendar = eventStore.defaultCalendarForNewEvents

let alarm1hour = EKAlarm(relativeOffset: 3600) //1 hour
let alarm1day = EKAlarm(relativeOffset: 86400) //1 day
event.addAlarm(alarm1day)
event.addAlarm(alarm1hour)

// prompt user to add event (to whatever calendar they want)
let controller = EKEventEditViewController()
controller.event = event
controller.eventStore = eventStore
controller.editViewDelegate = self

self.presentViewController(controller, animated: true, completion: nil)

} else {
self.dismissViewControllerAnimated(true, completion: {})
}
})
}

我假设 alarm = alert,但这似乎没有任何作用。我如何设置事件前 1 天的提醒,以及事件前 1 小时的另一个提醒?

最佳答案

来自documentation对于 EKAlarm(relativeOffset:):

Negative offset values fire before the start of the event, while positive values fire after the start.

我会尝试以下方法:

let alarm1hour = EKAlarm(relativeOffset: -3600) //1 hour
let alarm1day = EKAlarm(relativeOffset: -86400) //1 day

注意:由于夏令时的变化,您可能希望为“前一天”警报使用绝对时间。

关于ios - 如何在日历中设置默认提醒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42803475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com