@@ -484,6 +484,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
484
484
485
485
private var config : IterableConfig
486
486
private var apiEndPoint : String
487
+ private var hasHandledFirstForeground = false
487
488
488
489
/// Following are needed for handling pending notification and deep link.
489
490
static var pendingNotificationResponse : NotificationResponseProtocol ?
@@ -718,26 +719,32 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
718
719
}
719
720
720
721
@objc private func onAppDidBecomeActiveNotification( notification: Notification ) {
721
- // Always update the stored notification state
722
- notificationStateProvider. isNotificationsEnabled { [ weak self] isEnabled in
722
+ // Track first foreground handling
723
+ let isFirstForeground = !hasHandledFirstForeground
724
+ hasHandledFirstForeground = true
725
+
726
+ // Always check notification state
727
+ notificationStateProvider. isNotificationsEnabled { [ weak self] systemEnabled in
723
728
guard let self else { return }
724
729
725
- let previousState = self . localStorage. isNotificationsEnabled
726
-
727
- // Update stored state
728
- self . localStorage. isNotificationsEnabled = isEnabled
730
+ let storedEnabled = self . localStorage. isNotificationsEnabled
729
731
730
- // Only attempt registration/deregistration if state changed and auto-registration is enabled
731
- if previousState != isEnabled && self . config. autoPushRegistration {
732
- if isEnabled {
732
+ // Handle push registration/deregistration if needed
733
+ if self . config. autoPushRegistration && storedEnabled != systemEnabled {
734
+ if systemEnabled {
733
735
self . notificationStateProvider. registerForRemoteNotifications ( )
734
736
} else {
735
737
self . disableDeviceForCurrentUser ( )
736
738
}
737
739
}
738
740
739
- // Check remote configuration after push registration check
740
- self . checkRemoteConfiguration ( )
741
+ // Only fetch remote configuration on first foreground
742
+ if isFirstForeground {
743
+ self . checkRemoteConfiguration ( )
744
+ }
745
+
746
+ // Always update stored state (equivalent to SharedPreferences.Editor.putBoolean)
747
+ self . localStorage. isNotificationsEnabled = systemEnabled
741
748
}
742
749
}
743
750
0 commit comments