From 77f02273cffb6cf716af2f0a8d9bd93c84e48e23 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Sun, 30 Jun 2024 17:00:59 +0100 Subject: [PATCH] Show notifications banners when app is open --- ios-app/Tivi/Tivi/TiviApp.swift | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ios-app/Tivi/Tivi/TiviApp.swift b/ios-app/Tivi/Tivi/TiviApp.swift index 557a13839f..87e8055668 100644 --- a/ios-app/Tivi/Tivi/TiviApp.swift +++ b/ios-app/Tivi/Tivi/TiviApp.swift @@ -12,7 +12,7 @@ import FirebaseCrashlytics import SwiftUI import TiviKt -class AppDelegate: UIResponder, UIApplicationDelegate { +class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { // property of the app's AppDelegate var currentAuthorizationFlow: OIDExternalUserAgentSession? @@ -27,7 +27,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if !(FirebaseOptions.defaultOptions()?.apiKey?.isEmpty ?? true) { FirebaseApp.configure() } + + // Set the UNUserNotificationCenter delegate + UNUserNotificationCenter.current().delegate = self + + // Initiailize the AppInitializers applicationComponent.initializers.initialize() + return true } @@ -44,6 +50,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return false } + + func userNotificationCenter( + _: UNUserNotificationCenter, + willPresent _: UNNotification, + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void + ) { + // Show notification banners for notifications fired when the app is open + completionHandler([.banner]) + } + + func userNotificationCenter( + _: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void + ) { + // TODO + completionHandler() + } } @main