You first need a class that acts as the delegate for the userNotificationCenter.
class AppNotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// Customize the appearance of the notification, for example:
completionHandler([.banner, .sound])
}
}
Then you need to create an instance of this on your @main, and then tell the notification center what the delegate is.
let notificationDelegate = POSTAppNotificationDelegate()
init() {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.delegate = notificationDelegate
}