ios - 即使将重复间隔设置为工作日,UILocalNotification 也会每天触发

标签 ios iphone swift swift2 uilocalnotification

我正在尝试创建本地通知以在一周中的特定日期进行提醒。

这就是我到目前为止所要实现的目标

let calender = NSCalendar.currentCalendar()
        let notification = UILocalNotification()
        notification.soundName = UILocalNotificationDefaultSoundName

        notification.userInfo = NSDictionary(objects: [employee.deptID!], forKeys: [“deptID”]) as [NSObject : AnyObject]
        if #available(iOS 8.2, *) {
            notification.alertTitle = employee.Name
        } else {
        }
        notification.alertBody = "Its time to remind you about today’s target"

let dc = calender.components([NSCalendarUnit.Weekday , NSCalendarUnit.Hour , NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: timePicker.date)
                dc.weekday =  4
notification.repeatInterval = NSCalendarUnit.Weekday // TODO :
                notification.fireDate = calender.dateFromComponents(dc)
                UIApplication.sharedApplication().scheduleLocalNotification(notification)

但是,上面的代码每天都会在特定时间触发。我希望通知在特定工作日的特定时间触发。

上面的代码有什么错误?

最佳答案

尝试改变

notification.repeatInterval = NSCalendarUnit.Weekday

notification.repeatInterval = NSCalendarUnit.WeekOfYear

关于ios - 即使将重复间隔设置为工作日,UILocalNotification 也会每天触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708677/

相关文章:

html - uiwebview 和 CSS 文本阴影

iphone - UIAlertView 在未关闭时位于何处

ios - 来自 iOS 设备的 Azure Blob 存储 : Server failed to authenticate the request

iphone - NSDateFormat 有问题吗?

ios - 为什么 Swift 同时具有 NSDictionary 和 Dictionary 类?

ios - 如何在后台每 5 秒重复一次本地通知

ios - 运行时 Storyboard中设置的 UIButton 标题丢失

ios - 分页 UIScrollView "Prototype Pages"

ios - iOS8 CloudKit 可以支持幕后流媒体吗?

javascript - wkwebview:找出在 web View 中加载的内容是否为 PDF 并给出下载按钮