@@ -73,6 +73,9 @@ internal class PushNotificationMonitor: PushNotificationMonitoring, SocketSubscr
7373 }
7474
7575 private var deferredNotification : UserpilotNotification ?
76+ // Later, we could make this as configuration option,
77+ // to request the permission many times till we get it.
78+ private var didRequestPermissions = false
7679
7780 /// Initializes the `PushNotificationMonitor` with dependencies from the dependency injection container.
7881 ///
@@ -85,7 +88,6 @@ internal class PushNotificationMonitor: PushNotificationMonitoring, SocketSubscr
8588 self . socketManager = container. resolve ( SocketEvents . self)
8689
8790 PushNotificationAutoConfig . register ( observer: self )
88- refreshPushStatus ( )
8991 socketManager. registerCallback ( self )
9092 }
9193
@@ -134,6 +136,7 @@ internal class PushNotificationMonitor: PushNotificationMonitoring, SocketSubscr
134136
135137 /// Called when the socket is opened, and the push token is set if cached.
136138 func onSocketOpened( ) {
139+ refreshPushStatus ( )
137140 if let cachedToken {
138141 setPushToken ( cachedToken)
139142 }
@@ -146,6 +149,8 @@ internal class PushNotificationMonitor: PushNotificationMonitoring, SocketSubscr
146149 ///
147150 /// - Parameter completion: An optional closure that is called with the updated authorization status.
148151 func refreshPushStatus( completion: ( ( UNAuthorizationStatus ) -> Void ) ? = nil ) {
152+ if config. disableRequestPushPermission || didRequestPermissions { return }
153+ didRequestPermissions = true
149154 #if targetEnvironment(simulator)
150155 print ( " 🔧 Running on Simulator - push notification settings are not available. " )
151156 // Optionally simulate a status (e.g., .notDetermined or .authorized)
0 commit comments