我想在我设置的时间(小时,分钟)设置通知。但它显示错误:
func notification(story: Story) {
let dateComponents = NSDateComponents.init()
dateComponents.weekday = 5
dateComponents.hour = story.remindeAtHour
dateComponents.minute = story.remindeAtMinute
let notification = UILocalNotification()
notification.alertAction = "Title"
notification.alertBody = "It's time to take a photo"
notification.repeatInterval = NSCalendarUnit.WeekOfYear
notification.fireDate = dateComponents.calendar
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
答案 0 :(得分:1)
正如保罗在评论中指出的那样,错误信息告诉你错误。
您需要将通知的fireDate属性设置为日期(An NSDate
)。您需要一个将日期组件转换为NSDate
的方法。 NSCalendar方法dateFromComponents:
怎么样?