У меня проблемы с Local Notification
, у меня есть UIDatePicker
для времени установки уведомления, и у меня есть ViewController
для выбора дня, в который уведомление будет повторяться. Если я выбрал повторять каждую пятницу, это не будет работать, или другой день. Но на каждый день уведомления работают хорошо.
Мой код:
func createRequestNotifications() {
let content = UNMutableNotificationContent()
content.title = "Time to learn"
content.body = "Hey bro time to get some knolage)"
content.sound = UNNotificationSound.default()
let gregorian = Calendar(identifier: .gregorian)
let now = Date()
var components = gregorian.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now)
print(notification.day)
components.hour = notifTime
components.minute = notifMin
components.second = 0
components.day = notification.day
components.weekdayOrdinal = 10
components.timeZone = .current
let date = gregorian.date(from: components)!
if notification.day == 0 {
let triggerDaily = Calendar.current.dateComponents([.hour,.minute,.second,], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)
let request = UNNotificationRequest(identifier: "any", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
print("evry day")
} else {
let triggerDaily = Calendar.current.dateComponents([.hour,.minute,.second, .day,], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)
let request = UNNotificationRequest(identifier: "any", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
print("date setup")
}
}
notification.day
Это значение Int, которое устанавливается из другого ViewController
, в котором я выбираю повторение дня.
И я устал, потому что я понятия не имею, где проблема, для каждой даты работает уведомление, но для особого дня нет: (