ios - 每天在设定的时间用 swift 重复本地通知

标签 ios swift cocoa-touch uilocalnotification

我是 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

关于ios - 每天在设定的时间用 swift 重复本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30619998/

相关文章:

objective-c - UITableView/UITabBarController : trying to figure out a method to pass a variable to my destination controller when a row is selected

swift - 当之前在设备上授权 healthkit 访问时工作正常,但否则会崩溃

ios - 解析: fatal error: NSArray element failed to match the Swift Array Element type

iphone - 如何访问 applicationDidBecomeActive 上的远程推送通知数据?

ios - 在 Firebase 中注册 ios 应用程序时如何解决未知错误?

iphone - UILabel 中的动画计时器

ios - 如何同时管理来自两个不同 Controller 的两个 AFNetworking 操作

ios - 无法让 UIImageView 在 prepareForSegue 中发送

ios - iPhone - 沿触摸和拖动路径移动对象

ios - SpriteKit 中火箭的烟雾效果