我是 iOS 开发新手,但已经创建了该应用程序,并且正在尝试在设定的时间内创建每日通知。目前,通知在给定日期/时间执行一次。我不确定如何使用 RepeatInterval 方法每天安排它。每天重复通知的最佳方法是什么?任何帮助将不胜感激(Y)。
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)