在swift 3中,我如何安排特定日期的本地通知,如周一,周二和周六,如下午5点?
目前,我已安排本地通知我已设定的时间 .
let myOwnDate = Date()
dateFormatter.dateFormat = "dd/MM/yyyy"
let currentDate = dateFormatter.string(from: myOwnDate)
let dateTime = currentDate + " " + self.btnTime.titleLabel!.text!
dateFormatter.dateFormat = "dd/MM/yyyy hh:mm a"
let date = dateFormatter.date(from: dateTime)!
localNotification.fireDate = date
localNotification.repeatInterval = NSCalendar.Unit.weekday
localNotification.alertBody = "Your alarm is ringing!"
let app = UIApplication.shared
app.scheduleLocalNotification(localNotification)
但问题是这个通知全天都会触发 .
1 回答
您应该将repeatInterval设置为
而不是工作日 . 工作日每周都会开火 .
您还应该创建3个这样的通知,一个用于星期一,一个用于星期二,一个用于星期五 . 每个都会重复一周 .