「デバイスの再起動後、スケジュールされた通知はどうなりますか?」という質問に対する正確な答えを見つけようとしていました。
を使用しUNUserNotificationCenter
てすべての通知をスケジュールしましたが、スケジュールされた時間に基づいて毎日繰り返しトリガーされます。
これが私の書いたコード スニペットで、デバイスがオンのときに機能します。
func scheduleNotification() {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "This is the title"
content.body = "The is the body"
content.categoryIdentifier = "identifier"
content.userInfo = ["info":"B"]
content.sound = UNNotificationSound.default
var dateComponents = DateComponents()
dateComponents.hour = 0
dateComponents.minute = 29
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.removeAllPendingNotificationRequests()
center.add(request)
}