Skip to content

Commit bed600f

Browse files
chore: if journey disabled don't assign empty array
1 parent 8e91f1a commit bed600f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

HCaptcha/Classes/HCaptcha.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class HCaptcha: NSObject {
2727
/// The worker that handles webview events and communication
2828
let manager: HCaptchaWebViewManager
2929

30+
/// The user journey feature flag
31+
let userJourney: Bool
32+
3033
/**
3134
- parameters:
3235
- apiKey: The API key sent to the HCaptcha init
@@ -114,16 +117,17 @@ public class HCaptcha: NSObject {
114117

115118
Log.debug(".init with: \(config)")
116119

117-
self.init(manager: HCaptchaWebViewManager(config: config))
120+
self.init(manager: HCaptchaWebViewManager(config: config), userJourney: userJourney)
118121
}
119122

120123
/**
121124
- parameter manager: A HCaptchaWebViewManager instance.
122125

123126
Initializes HCaptcha with the given manager
124127
*/
125-
init(manager: HCaptchaWebViewManager) {
128+
init(manager: HCaptchaWebViewManager, userJourney: Bool) {
126129
self.manager = manager
130+
self.userJourney = userJourney
127131
}
128132

129133
/**
@@ -169,7 +173,9 @@ public class HCaptcha: NSObject {
169173
completion: @escaping (HCaptchaResult) -> Void) {
170174
Log.debug(".validate on: \(String(describing: view)) verifyParams: \(verifyParams)")
171175

172-
verifyParams.userJourney = HCaptchaJourneys.drainEvents()
176+
if userJourney {
177+
verifyParams.userJourney = HCaptchaJourneys.drainEvents()
178+
}
173179

174180
manager.completion = completion
175181
manager.verifyParams = verifyParams

HCaptcha/Classes/HCaptchaJourneys.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public enum HCaptchaJourneys {
2323
}
2424

2525
/// Returns collected events as raw data ([] when unavailable/empty).
26-
public static func drainEvents() -> [Any] {
26+
public static func drainEvents() -> [Any]? {
2727
guard let impl = NSClassFromString("HCaptchaJourneysImpl") else { return [] }
2828
let sel = NSSelectorFromString("drainEvents")
2929
guard let unmanaged = (impl as AnyObject).perform(sel),
3030
let anyObj = unmanaged.takeUnretainedValue() as? [Any],
3131
JSONSerialization.isValidJSONObject(anyObj) else {
32-
return []
32+
return nil
3333
}
3434
return anyObj
3535
}

0 commit comments

Comments
 (0)