gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:20:49 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com