如何在 Swift 中每周重复 LocalNotification?
How to repeat LocalNotification Weekly in Swift?
我想每周重复一次本地通知。
let notification = UILocalNotification()
notification.alertBody = "Notification"
notification.alertTitle = "Notification Title"
notification.repeatInterval = NSCalendarUnit.Weekday
notification.fireDate = notificationDate
notification.soundName = UILocalNotificationDefaultSoundName
notification.category = "Events"
UIApplication.sharedApplication().scheduleLocalNotification(notification)
但是这是每天重复而不是每周重复?
您需要使用notif.repeatInterval = NSCalendarUnit.WeekOfMonth
您应该使用 NSCalendarUnit.WeekOfYear
而不是 NSCalendarUnit.Weekday
。
请注意 weekday
表示一周中的某一天(即每天)和 weekOfYear
表示一周的区别。
我想每周重复一次本地通知。
let notification = UILocalNotification()
notification.alertBody = "Notification"
notification.alertTitle = "Notification Title"
notification.repeatInterval = NSCalendarUnit.Weekday
notification.fireDate = notificationDate
notification.soundName = UILocalNotificationDefaultSoundName
notification.category = "Events"
UIApplication.sharedApplication().scheduleLocalNotification(notification)
但是这是每天重复而不是每周重复?
您需要使用notif.repeatInterval = NSCalendarUnit.WeekOfMonth
您应该使用 NSCalendarUnit.WeekOfYear
而不是 NSCalendarUnit.Weekday
。
请注意 weekday
表示一周中的某一天(即每天)和 weekOfYear
表示一周的区别。