1
我在我的应用程序中安排了一批通知,其中一些带有重复间隔,其他的只是在特定日期发生的一次触发。我用这个方法来创建通知设置我的通知:UILocalNotification repeatInterval打破时区和fireDate
func notification(date: Date, repeatUnit: NSCalendar.Unit?) -> UILocalNotification {
let notification = UILocalNotification()
notification.category = "ReminderCategory"
notification.alertTitle = "Test"
notification.alertBody = "Test Body"
notification.soundName = "Sound1.m4a"
notification.fireDate = date
notification.repeatInterval = repeatUnit ?? NSCalendar.Unit(rawValue: 0)
notification.timeZone = TimeZone.init(secondsFromGMT: 0)!
return notification
}
的通知消防在正确的时间(本地时区)如果repeatUnit
变量被设置为任何NSCalendar.Unit
单位。
但是,如果我没有设置repeatInterval
,通知fireDates以某种方式设置在过去,并且在我安排通知后立即触发。
有没有人有任何想法是怎么回事?
如果你比较'date'做了'Date.date()',是'date'在过去吗? – Larme