【发布时间】:2016-12-04 19:43:37
【问题描述】:
我的代码有问题。
我想在 xcode7 中设置本地通知,我正在开发一个日历,您可以在其中放置大学的课程,问题是我从 json 数据库中获取日程安排,我想在开课前 15 分钟通知课程开始了,但我不知道为什么我的代码不起作用。
这是我想在每周一 13:40 重复通知的示例。
我只能设置日期和时间吗?还是我也应该指定月份和年份?
var dateComp:NSDateComponents = NSDateComponents()
dateComp.day = 01;
dateComp.hour = 13;
dateComp.minute = 40;
dateComp.timeZone = NSTimeZone.systemTimeZone()
var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
var date:NSDate = calender.dateFromComponents(dateComp)!
let notification = UILocalNotification()
notification.fireDate = date
notification.alertBody = "Swipe to unlock"
notification.alertAction = "You've got a class soon!"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["CustomField1": "w00t"]
notification.repeatInterval = NSCalendarUnit.WeekOfYear
UIApplication.sharedApplication().scheduleLocalNotification(notification)
【问题讨论】:
-
您需要将通知时区设置为本地
标签: ios swift swift2 uilocalnotification