ios - UILocalNotification 每周重复一次

标签 ios swift notifications uilocalnotification nscalendar

我想设置一个UILocalNotification,它每周每周五自动重复一次。我目前正在使用下面的代码每天同时重复一次通知,但我不确定如何在本周创建此通知。

谢谢

let calendar: NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
                let now: NSDate! = NSDate()
                let notifDate = calendar.dateBySettingHour(19, minute: 0, second: 0, ofDate: now, options: NSCalendarOptions.MatchFirst)!

                var notification = UILocalNotification()
                notification.category = "Reminder"
                notification.alertTitle = "Alert"
                notification.alertBody = "Alert body"
                notification.fireDate = notifDate
                notification.soundName = UILocalNotificationDefaultSoundName
                notification.repeatInterval = NSCalendarUnit.Day
                UIApplication.sharedApplication().scheduleLocalNotification(notification)

最佳答案

检查 Apple Docs这里是 UILocalNotification

这就是您将其设置为每周重复的方式。

notification.repeatInterval = NSCalendarUnit.WeekOfYear;

附言。此代码将在创建通知的当天创建一个通知,而不仅仅是在星期五。需要考虑的事情。

let now: NSDate! = NSDate() //whatever today's day is and it could be any day between M-Sun
let notifDate = calendar.dateBySettingHour(19, minute: 0, second: 0, ofDate: now, options: NSCalendarOptions.MatchFirst)!

关于ios - UILocalNotification 每周重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38334300/

相关文章:

spring - 如何在 IntelliJ IDEA 中选择配置文件?

ios - UICollectionViewCell - 内容不会与单元格的 contentView 一起动画

ios - 有人成功使用 pyqtdeploy 将 pyqt 部署到 iOS 吗?

ios - UICollectionView

android 在通知中嵌入换行符

java - android AlarmManager setRepating延时问题

ios - Flutter pod 安装问题和 ios 应用程序未运行

ios - 以编程方式创建的 uiview 在第一次单击时没有响应

ios - 检查多个数组的特定值并计算另一个值的平均值 - swift

ios - 如何快速将分钟添加到当前时间