如何在特定日期而不是当前工作日触发本地通知

时间:2018-02-21 06:49:13

标签: ios swift3 uilocalnotification

我正在开发一个闹钟应用。在设置警报时,用户选择存储在阵列中的日期。但是当我在通知时尝试放置价值时,我没有得到正确的工作日。在我的代码中,我在“daysValue”([0,1,1,1,0,0,0]中获得工作日,意味着警报设置为星期一,星期二和星期三)但我不知道如何通过触发日期中的这些值。这是代码

var daysValue: [Int]
        daysValue = AlarmController.shared.days

        print(daysValue)
        for _ in daysValue
        {
            for ind in 0...countNum
            {
                guard let fireDate = alarm.fireDate else { return }
                print(fireDate)
                let date = fireDate.addingTimeInterval((1.0*Double(ind)) * 60.0)
                print(date)
                let weekday = Calendar.current.component(.weekday, from: date)
                print(weekday)



                let triggerDate = Calendar.current.dateComponents([.weekday, .hour, .minute, .second], from: date)
                DispatchQueue.main.async
                    {
                        print(triggerDate)
                        let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: true)
                        let request = UNNotificationRequest(identifier: "\(alarm.uuid)\(ind)", content: notificationContent, trigger: trigger)
                        UNUserNotificationCenter.current().add(request)
                        {
                            (error) in
                            if let error = error
                            {
                                print("Unable to add notification request, \(error.localizedDescription)")
                            }
                        }
                    }

            }

        }

0 个答案:

没有答案