如何在Swift中重复LocalNotification周刊?

时间:2016-03-13 18:52:49

标签: ios swift uilocalnotification

我试图每周重复一次本地通知。

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)

但这是每天重复而不是每周重复一次?

2 个答案:

答案 0 :(得分:3)

您应该使用NSCalendarUnit.WeekOfYear代替NSCalendarUnit.Weekday

注意weekday表示一周中的一天(即每天)与表示一周的weekOfYear之间的差异。

答案 1 :(得分:0)

您需要使用notif.repeatInterval = NSCalendarUnit.WeekOfMonth