I want to set a local notification for a specific time, but I have concerns about it. For example, when I set the local notification for once and I say that I scheduled it and suddenly the user's phone turns off, what's gonna happen? I'm sure this notification data is just available in the memory and it will disappear when the user's phone turns off.
And I know every time I set the same date, I am gonna get more notifications at that time. I just want one notification, but as I told you, I don't know how to handle the possibilities for the user.
Here is my sample code :
func scheduleNotification(inSeconds : TimeInterval, completion : @escaping (_ Success : Bool) -> ()){
let notif = UNMutableNotificationContent()
notif.title = "New notification"
notif.subtitle = "Cool!"
notif.body = "I liked it!!!!"
let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: inSeconds, repeats: false)
let request = UNNotificationRequest(identifier: "myNotification", content: notif, trigger: notifTrigger)
UNUserNotificationCenter.current().add(request) { (error) in
if error != nil{
print(error!)
completion(false)
}else{
completion(true)
}
}
}