I am working on a timer application that should terminate if the user leaves the app. I want a notification to be sent to the user when they leave the application. This notification WARNS the user that the timer will terminate if they do not return to the app immediately I have look at UNNotficationTrigger's but not of what i have tried repeats the notification if the user is to be warned more than once.
How to i detect when the user is outside the application, then send a notification warning them to return to the app?? Thank you in advance
Code:
@IBAction func start(_ sender: Any) {
startTimer()
let content = UNMutableNotificationContent()
content.title = "WARNING: Return to 4ocus"
content.subtitle = ""
content.body = "Go back to 4ocus or risk losing 4ocus points"
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
@IBAction func start(_ sender: Any) {
startTimer()
let content = UNMutableNotificationContent()
content.title = "WARNING: Return to 4ocus"
content.subtitle = ""
content.body = "Go back to 4ocus or risk losing 4ocus points"
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)