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)
}
最佳答案
正如Paul w在评论中指出的那样,错误消息告诉您出了什么问题。
您需要将通知的fireDate属性设置为日期(NSDate
)。您需要一种将日期成分转换为NSDate
的方法。 NSCalendar方法dateFromComponents:
怎么样?
关于ios - 在特定时间设置通知Swift,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34446772/