File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import SwiftUI
33import UserNotifications
44
55@Observable
6- final class ThermalMonitor {
6+ final class ThermalMonitor : NSObject , UNUserNotificationCenterDelegate {
77 // MARK: - Constants
88 private static let historyDurationSeconds : TimeInterval = 600 // 10 minutes
99 private static let pollIntervalSeconds : TimeInterval = 2.0
@@ -74,11 +74,23 @@ final class ThermalMonitor {
7474 return Date ( ) . timeIntervalSince ( first. timestamp)
7575 }
7676
77- init ( ) {
77+ override init ( ) {
78+ super. init ( )
79+ UNUserNotificationCenter . current ( ) . delegate = self
7880 requestNotificationPermission ( )
7981 startMonitoring ( )
8082 }
8183
84+ // MARK: - UNUserNotificationCenterDelegate
85+
86+ func userNotificationCenter(
87+ _ center: UNUserNotificationCenter ,
88+ willPresent notification: UNNotification ,
89+ withCompletionHandler completionHandler: @escaping ( UNNotificationPresentationOptions ) -> Void
90+ ) {
91+ completionHandler ( [ . banner, . sound] )
92+ }
93+
8294 deinit {
8395 timer? . invalidate ( )
8496 }
You can’t perform that action at this time.
0 commit comments