我是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
I am new to iOS development, but have created the app and I am trying to create a daily notification for a set time. Currently the notification executes once for the given date/time. I am unsure how to use the repeatInterval method to schedule it daily. What is the best method to repeat the notification daily ? any help would be much appreciated (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)解决方案
You have to provide an NSCalendarUnit value like "HourCalendarUnit" or "DayCalendarUnit" for repeating a notification.
Just add this code to repeat the local notification daily :
notification.repeatInterval = NSCalendarUnit.CalendarUnitDay
更多推荐
每天在设定的时间与swift重复本地通知
发布评论