我是iOS开发的新手,但是已经创建了该应用程序,并且我试图在设定的时间创建每日通知。当前,通知针对给定的日期/时间执行一次。我不确定如何使用repeatInterval方法每天进行调度。每天重复通知的最佳方法是什么?任何帮助将不胜感激(是)。
var dateComp:NSDateComponents = NSDateComponents() dateComp.year = 2015; dateComp.month = 06; dateComp.day = 03; dateComp.hour = 12; dateComp.minute = 55; dateComp.timeZone = NSTimeZone.systemTimeZone() var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! var date:NSDate = calender.dateFromComponents(dateComp)! var notification:UILocalNotification = UILocalNotification() notification.category = "Daily Quote" notification.alertBody = quoteBook.randomQuote() notification.fireDate = date notification.repeatInterval = UIApplication.sharedApplication().scheduleLocalNotification(notification)
您必须提供NSCalendarUnit值(例如“ HourCalendarUnit”或“ DayCalendarUnit”)以重复通知。
只需添加以下代码即可每天重复本地通知:
notification.repeatInterval = NSCalendarUnit.CalendarUnitDay