【发布时间】:2016-11-06 16:13:35
【问题描述】:
我正在尝试安排本地通知,以便它在晚上 9:00 发生并每周重复一次。我有以下代码,并且一直收到一条错误消息,提示“无法将 NSDateComponents 类型的值分配给 .fireDate。我知道 .fireDate 只会接受 NSDate 类型,但是。我想不出一种方法来设置小时变量和分钟变量对于 NSDate 类型,因为我认为不可能这样做。
func Notification(){
let dateComponents = NSDateComponents()
dateComponents.day = 4
dateComponents.month = 7
dateComponents.year = 2016
dateComponents.hour = 21
dateComponents.minute = 00
let Notification = UILocalNotification()
Notification.alertAction = "Go Back To App"
Notification.alertBody = "Did you complete your HH and QC?"
Notification.repeatInterval = NSCalendarUnit.WeekOfYear
Notification.timeZone = NSTimeZone.defaultTimeZone()
Notification.fireDate = dateComponents
UIApplication.sharedApplication().scheduleLocalNotification(Notification)
}
【问题讨论】:
-
谷歌日历方法 dateFromComponents
标签: ios xcode swift nsdatecomponents localnotification