Ios UILocalNotification每周重复一次
我想设置一个Ios UILocalNotification每周重复一次,ios,swift,notifications,uilocalnotification,nscalendar,Ios,Swift,Notifications,Uilocalnotification,Nscalendar,我想设置一个UILocalNotification,它将在每个星期五自动重复一次。我目前正在使用下面的代码在同一时间每天重复一次通知,但我不知道如何为本周创建此通知 多谢各位 let calendar: NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) let now: NSDate! = NSDate() let notifDat
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)
检查这里的UILocalNotification
这是您将其设置为每周重复的方式
notification.repeatInterval = NSCalendarUnit.WeekOfYear;
注:此代码将在创建notif的当天创建notif,而不仅仅是在周五。需要考虑的事情p>
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)!
将repeatInterval更改为NSCalendarUnit。一年中的一周。它将在每周的同一时间重复。似乎没有“NSCalendarUnit.week”。当使用有关错误消息的行更改为:使用未解析标识符“kCFCalendarUnitWeek”Try-NSWeekCalendarUnit时,出现一个错误,该错误表示:类型“NSCalendarUnit”没有成员“Week”或“NSCalendarUnit.WeekOfYear”