gpt4 book ai didi

ios - 即使将 repeatInterval 设置为工作日后,UILocalNotification 每天都会触发

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

我正在尝试为一周中特定几天的提醒创建本地通知。

这就是我到目前为止所做的事情

let calender = NSCalendar.currentCalendar()
let notification = UILocalNotification()
notification.soundName = UILocalNotificationDefaultSoundName

notification.userInfo = NSDictionary(objects: [employee.deptID!], forKeys: [“deptID”]) as [NSObject : AnyObject]
if #available(iOS 8.2, *) {
notification.alertTitle = employee.Name
} else {
}
notification.alertBody = "Its time to remind you about today’s target"

let dc = calender.components([NSCalendarUnit.Weekday , NSCalendarUnit.Hour , NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: timePicker.date)
dc.weekday = 4
notification.repeatInterval = NSCalendarUnit.Weekday // TODO :
notification.fireDate = calender.dateFromComponents(dc)
UIApplication.sharedApplication().scheduleLocalNotification(notification)

但是,上面的代码每天都会在那个特定时间触发。我希望通知在特定工作日的特定时间触发。

上面的代码有什么错误?

最佳答案

尝试改变

notification.repeatInterval = NSCalendarUnit.Weekday

notification.repeatInterval = NSCalendarUnit.WeekOfYear

关于ios - 即使将 repeatInterval 设置为工作日后,UILocalNotification 每天都会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708677/

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