Skip to content

Commit

Permalink
Local Notification: Cancel notification
Browse files Browse the repository at this point in the history
  • Loading branch information
SajidHShanta committed Mar 4, 2023
1 parent 60566ce commit 455dd59
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class NotificationManager {
trigger: trigger)
UNUserNotificationCenter.current().add(request)
}

func cancelNotification() {
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
}
}

struct LocalNotification_Learn: View {
Expand All @@ -75,6 +80,11 @@ struct LocalNotification_Learn: View {
Button("Schedule Notification") {
NotificationManager.instance.scheduleNotification()
}

Button("Cancel All Notification") {
NotificationManager.instance.cancelNotification()
}
.foregroundColor(.red)
}
.onAppear {
UIApplication.shared.applicationIconBadgeNumber = 0
Expand Down

0 comments on commit 455dd59

Please sign in to comment.