0
我的代码有问题。如何在swift中设置每周本地通知
我想在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)
您需要设置您的通知时区当地 –
http://stackoverflow.com/a/34575836/2303865 –