The local notification is supposed to fire at 25-9-2021. Here is the print object of fire time
▿ year: 2021 month: 9 day: 26 isLeapMonth: false
- year : 2021
- month : 9
- day : 25
- isLeapMonth : false
let content = UNMutableNotificationContent()
content.title = "Test title"
content.body = "sample test body"
var trigger:UNCalendarNotificationTrigger
let n = 1
let nextTriggerDate = Calendar.current.date(byAdding: .day, value: n, to: Date())!
let comps = Calendar.current.dateComponents([.year, .month, .day], from: nextTriggerDate)
trigger = UNCalendarNotificationTrigger(dateMatching: comps, repeats: false)
content.subtitle = "Sub title-Date-NonRepeat"
let request = UNNotificationRequest(identifier: "test.my.example", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { Error in
if let err = Error {
print("Notification Error:\(String(describing: err))")
}
}
Again I added time with Date with below code changes
var comps = Calendar.current.dateComponents([.year, .month, .day], from: nextTriggerDate)
comps.day = 25
comps.hour = 12
comps.minute = 17
comps.second = 10
Here is PO of comps variable
var comps = Calendar.current.dateComponents([.year, .month, .day], from: nextTriggerDate) comps.day = 25 comps.hour = 12 comps.minute = 17 comps.second = 10
I have given just date to see if it fires and I have given just date and time to see if it fires and I'm doing the whole thing in main thread and it's not working
Can someone make me understand what am I doing wrong here
You likely aren't requesting permission first
Run this code. Click on "Request Permission" first then click on "Add custom trigger" you should see your notification in the console when you click on "print"