@@ -80,67 +80,72 @@ public final class AuthClient: Sendable {
8080 observeAppLifecycleChanges ( )
8181 }
8282
83- private func observeAppLifecycleChanges( ) {
84- #if canImport(UIKit)
85- #if canImport(WatchKit)
86- if #available( watchOS 7 . 0 , * ) {
83+ #if canImport(ObjectiveC)
84+ private func observeAppLifecycleChanges( ) {
85+ #if canImport(UIKit)
86+ #if canImport(WatchKit)
87+ if #available( watchOS 7 . 0 , * ) {
88+ NotificationCenter . default. addObserver (
89+ self ,
90+ selector: #selector( handleDidBecomeActive) ,
91+ name: WKExtension . applicationDidBecomeActiveNotification,
92+ object: nil
93+ )
94+ NotificationCenter . default. addObserver (
95+ self ,
96+ selector: #selector( handleWillResignActive) ,
97+ name: WKExtension . applicationWillResignActiveNotification,
98+ object: nil
99+ )
100+ }
101+ #else
87102 NotificationCenter . default. addObserver (
88103 self ,
89104 selector: #selector( handleDidBecomeActive) ,
90- name: WKExtension . applicationDidBecomeActiveNotification ,
105+ name: UIApplication . didBecomeActiveNotification ,
91106 object: nil
92107 )
93108 NotificationCenter . default. addObserver (
94109 self ,
95110 selector: #selector( handleWillResignActive) ,
96- name: WKExtension . applicationWillResignActiveNotification ,
111+ name: UIApplication . willResignActiveNotification ,
97112 object: nil
98113 )
99- }
100- #else
114+ #endif
115+ #elseif canImport(AppKit)
101116 NotificationCenter . default. addObserver (
102117 self ,
103118 selector: #selector( handleDidBecomeActive) ,
104- name: UIApplication . didBecomeActiveNotification,
119+ name: NSApplication . didBecomeActiveNotification,
105120 object: nil
106121 )
107122 NotificationCenter . default. addObserver (
108123 self ,
109124 selector: #selector( handleWillResignActive) ,
110- name: UIApplication . willResignActiveNotification,
125+ name: NSApplication . willResignActiveNotification,
111126 object: nil
112127 )
113128 #endif
114- #elseif canImport(AppKit)
115- NotificationCenter . default. addObserver (
116- self ,
117- selector: #selector( handleDidBecomeActive) ,
118- name: NSApplication . didBecomeActiveNotification,
119- object: nil
120- )
121- NotificationCenter . default. addObserver (
122- self ,
123- selector: #selector( handleWillResignActive) ,
124- name: NSApplication . willResignActiveNotification,
125- object: nil
126- )
127- #endif
128- }
129-
130- @objc
131- private func handleDidBecomeActive( ) {
132- if configuration. autoRefreshToken {
133- startAutoRefresh ( )
134129 }
135- }
136130
137- @objc
138- private func handleWillResignActive( ) {
139- if configuration. autoRefreshToken {
140- stopAutoRefresh ( )
131+ @objc
132+ private func handleDidBecomeActive( ) {
133+ if configuration. autoRefreshToken {
134+ startAutoRefresh ( )
135+ }
141136 }
142- }
143137
138+ @objc
139+ private func handleWillResignActive( ) {
140+ if configuration. autoRefreshToken {
141+ stopAutoRefresh ( )
142+ }
143+ }
144+ #else
145+ private func observeAppLifecycleChanges( ) {
146+ // no-op
147+ }
148+ #endif
144149 /// Listen for auth state changes.
145150 /// - Parameter listener: Block that executes when a new event is emitted.
146151 /// - Returns: A handle that can be used to manually unsubscribe.
0 commit comments