Skip to content

Commit

Permalink
Local Notification: schedule notification with time
Browse files Browse the repository at this point in the history
  • Loading branch information
SajidHShanta committed Mar 4, 2023
1 parent 5522cb4 commit 148f543
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ class NotificationManager {
}
}
}

func scheduleNotification() {
let content = UNMutableNotificationContent()
content.title = "This is Notification Title"
content.subtitle = "This is subtitle!"
content.sound = .default
content.badge = 1

// trigger can be 3 types:
// - time
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5.0, repeats: false)
// - calender
// - location

let request = UNNotificationRequest(
identifier: UUID().uuidString, // random id. because in this scenario we don't need to track
content: content,
trigger: trigger)
UNUserNotificationCenter.current().add(request)
}
}

struct LocalNotification_Learn: View {
Expand All @@ -30,6 +50,10 @@ struct LocalNotification_Learn: View {
Button("Request Permission") {
NotificationManager.instance.requestAuthorization()
}

Button("Schedule Notification") {
NotificationManager.instance.scheduleNotification()
}
}
}
}
Expand Down

0 comments on commit 148f543

Please sign in to comment.