Hi, I have this:
import SwiftUI
import UserNotifications
struct ContentView: View {
var body: some View {
VStack {
Button("Request Permission") {
RequestNotificationsAccess()
}
Button("Schedule Notification") {
ScheduleNotification()
}
}
}
}
func RequestNotificationsAccess() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
if success {
print("All set!")
} else if let error = error {
print(error.localizedDescription)
}
}
}
func ScheduleNotification() {
let content = UNMutableNotificationContent()
content.title = "Title:"
content.subtitle = "some text"
content.sound = UNNotificationSound.default
// show this notification five seconds from now
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
// add our notification request
UNUserNotificationCenter.current().add(request)
}
It works great but when I click multiple times on the button, the notification appears multiple times, how can I track if it was fired already and if so, don't display anything?
Thanks