我想设置一个UILocalNotification
,它每周每周五自动重复一次。我目前正在使用下面的代码每天同时重复一次通知,但我不确定如何在本周创建此通知。
谢谢
let calendar: NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
let now: NSDate! = NSDate()
let notifDate = calendar.dateBySettingHour(19, minute: 0, second: 0, ofDate: now, options: NSCalendarOptions.MatchFirst)!
var notification = UILocalNotification()
notification.category = "Reminder"
notification.alertTitle = "Alert"
notification.alertBody = "Alert body"
notification.fireDate = notifDate
notification.soundName = UILocalNotificationDefaultSoundName
notification.repeatInterval = NSCalendarUnit.Day
UIApplication.sharedApplication().scheduleLocalNotification(notification)
最佳答案
检查 Apple Docs这里是 UILocalNotification
这就是您将其设置为每周重复的方式。
notification.repeatInterval = NSCalendarUnit.WeekOfYear;
附言。此代码将在创建通知的当天创建一个通知,而不仅仅是在星期五。需要考虑的事情。
let now: NSDate! = NSDate() //whatever today's day is and it could be any day between M-Sun
let notifDate = calendar.dateBySettingHour(19, minute: 0, second: 0, ofDate: now, options: NSCalendarOptions.MatchFirst)!
关于ios - UILocalNotification 每周重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38334300/