如何在swift中安排每日推送通知?

时间:2015-07-28 00:11:48

标签: ios objective-c swift ios7 ios8

我希望我的应用程序每天晚上13点通知用户。我把它放在我的app委托中:

    func Notification() {
    var Notification = UILocalNotification()
    Notification.alertAction = "New Question!"
    Notification.alertBody = "Solve the new question!"


    Notification.fireDate = NSDate(timeIntervalSinceNow: 0)

    UIApplication.sharedApplication().scheduleLocalNotification(Notification)
}

并且在我的应用程序中有了didFinishLaunching:

    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge | UIUserNotificationType.Sound, categories: nil))

我必须做什么才能确保我的通知每天都会启动?

1 个答案:

答案 0 :(得分:0)

只设置过去的日期,晚上13点, 并将repeatInterval设置为.CalendarUnitDay

notification.repeatInterval = .CalendarUnitDay;
notification.fireDate = NSDate(timeIntervalSince1970: 60*60*10)