Я пытаюсь сделать уведомление, которое будет срабатывать каждый день в одно и то же время (7:00 утра).Я могу получить уведомление для запуска, если я использую UNTimeIntervalNotificationTrigger
, но не UNCalendarNotificationTrigger
, что я действительно хочу.Это то, что у меня сейчас:
В AppDelegate.swift у меня есть:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (didAllow, error) in
if error != nil {
print(error as Any)
}
}
return true
}
И я вспомнил, как импортировать UserNotifications
тоже
Когда пользователь нажимает кнопкув ViewController.swift это выполняется:
let content = UNMutableNotificationContent()
content.title = "Do your daily review"
content.badge = 1
let triggerTime = DateComponents.init(hour: 7, minute: 0, second: 0)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerTime, repeats: true)
let request = UNNotificationRequest(identifier: "dailyNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil
Не могли бы вы объяснить мне, что здесь не так и почему UNTimeIntervalNotificationTrigger
работает, а UNCalendarNotificationTrigger
нет?