Skip to content

Commit c649422

Browse files
Release 1.0.12
🔧 Add configuration option to disable request push notifications permission ⬆️ Bump SDK version
1 parent 4541f37 commit c649422

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

Sources/Userpilot/Experiences/ExperiencesPublisher.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,19 @@ extension ExperiencesPublisher {
787787
* Retains only the last experience and processes it.
788788
*/
789789
private func processNextPendingExperiences() {
790-
if pendingExperiences.isEmpty { return }
791-
experienceQueue.async { [weak self] in
792-
guard let self else { return }
793-
if let lastContent = self.pendingExperiences.last, self.pendingExperiences.count > 1 {
794-
self.pendingExperiences = [lastContent]
790+
tryCatch {
791+
if pendingExperiences.isEmpty { return }
792+
experienceQueue.async { [weak self] in
793+
guard let self else { return }
794+
if pendingExperiences.count == 1 {
795+
pendingExperiences.removeAll()
796+
} else {
797+
if let lastContent = self.pendingExperiences.last, self.pendingExperiences.count > 1 {
798+
self.pendingExperiences = [lastContent]
799+
self.openExperienceFlow()
800+
}
801+
}
795802
}
796-
self.openExperienceFlow()
797803
}
798804
}
799805

Sources/Userpilot/PushNotification/PushNotificationMonitor.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)

Sources/Userpilot/Userpilot+Config.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public extension Userpilot {
2626
/// Userpilot SDK logger
2727
var logger: Logging = OSLog.disabled
2828

29+
/// Disable request push notifications permission by SDK.
30+
var disableRequestPushPermission: Bool = false
31+
2932
/// Create an Userpilot SDK configuration
3033
/// - Parameter token: Userpilot Account Token, copied from the Environments settings page.
3134
@objc
@@ -43,6 +46,19 @@ public extension Userpilot {
4346
logger = isEnabled ? OSLog(userpilotCategory: GeneralConstants.USERPILOT_LOGGING_CATEOGRY) : .disabled
4447
return self
4548
}
49+
50+
/// Disables the automatic request for push notification permissions.
51+
///
52+
/// By default, the SDK may prompt the user to grant push notification permissions.
53+
/// Calling this method prevents the SDK from showing that prompt automatically.
54+
/// - Returns: The `Configuration` object, allowing for method chaining.
55+
@discardableResult
56+
@objc
57+
public func disableRequestPushNotificationsPermission() -> Self {
58+
self.disableRequestPushPermission = true
59+
return self
60+
}
61+
4662
}
4763

4864
}

Sources/Userpilot/Userpilot.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public class Userpilot: NSObject {
109109
container.registerEager(DataStoring.self, initializer: Storage.init)
110110
container.registerEager(AnalyticsPublishing.self, initializer: AnalyticsPublisher.init)
111111
container.registerEager(SessionMonitoring.self, initializer: SessionMonitor.init)
112-
container.registerEager(ExperiencesPublishing.self, initializer: ExperiencesPublisher.init)
113112
container.registerEager(PushNotificationMonitoring.self, initializer: PushNotificationMonitor.init)
113+
container.registerEager(ExperiencesPublishing.self, initializer: ExperiencesPublisher.init)
114114
}
115115
}
116116

Sources/Userpilot/Version.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ import Foundation
1414
/// The current version of the Userpilot SDK.
1515
private let versionMajor = "1"
1616
private let versionMinor = "0"
17-
private let versionPatch = "11"
17+
private let versionPatch = "12"
1818
let userpilotVersion = "\(versionMajor).\(versionMinor).\(versionPatch)"

Userpilot.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pod::Spec.new do |spec|
22

33
spec.name = "Userpilot"
44
spec.module_name = "Userpilot"
5-
spec.version = "1.0.11"
5+
spec.version = "1.0.12"
66
spec.summary = "Userpilot iOS SDK allows you to integrate Userpilot experiences into your native iOS apps"
77

88
spec.description = <<-DESC

0 commit comments

Comments
 (0)