我正在尝试创建本地通知以在一周中的特定日期进行提醒。
这就是我到目前为止所要实现的目标
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 - 即使将重复间隔设置为工作日,UILocalNotification 也会每天触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708677/