In my iOS app, I want to show a local notification when the user clicks a button.
But according to the documentation, it looks like the notification can only be displayed:
- after a certain amount of time or on a specific date
- when the user enters or exits a specific location
- when the app gets a push notification
The best I can do so far is:
// content:
let content = UNMutableNotificationContent()
content.categoryIdentifier = "test_category"
content.title = "Title"
content.subtitle = "Subtitle"
content.body = "Notification body"
content.sound = UNNotificationSound.default
// trigger:
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
So how can I show a local notification on iOS when the user clicks a button?
Thanks.