Skip to content

Commit 4432d36

Browse files
fix: resolve swift-lint issues, increase pod size
- Fix all SwiftLint violations (line length, alignment, trailing newlines) - Increase fastlane pod size limit to 200KB - Refactor HCaptchaWebViewManager to reduce file size (410→331 lines) - Fix Carthage Xcode to compile on 14.x version
1 parent 8d9eace commit 4432d36

File tree

10 files changed

+322
-258
lines changed

10 files changed

+322
-258
lines changed

Example/HCaptcha_Tests/Journeylitics/JourneyliticsHooks__Tests.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,18 @@ final class JourneyliticsHooks__Tests: XCTestCase {
215215

216216
UIApplication.jl_installHook()
217217
let target = SpyActionTarget()
218-
let item = UIBarButtonItem(title: "Tap", style: .plain, target: target, action: #selector(SpyActionTarget.barTapped(_:)))
219-
_ = UIApplication.shared.sendAction(#selector(SpyActionTarget.barTapped(_:)), to: target, from: item, for: nil)
218+
let item = UIBarButtonItem(
219+
title: "Tap",
220+
style: .plain,
221+
target: target,
222+
action: #selector(SpyActionTarget.barTapped(_:))
223+
)
224+
_ = UIApplication.shared.sendAction(
225+
#selector(SpyActionTarget.barTapped(_:)),
226+
to: target,
227+
from: item,
228+
for: nil
229+
)
220230

221231
XCTAssertTrue(target.barInvoked)
222232
guard let event = recorder.events.last else { return XCTFail("No events recorded") }
@@ -327,7 +337,9 @@ private final class SpyTableDelegate: NSObject, UITableViewDelegate {
327337

328338
private final class SpyCollectionDelegate: NSObject, UICollectionViewDelegate {
329339
var lastSelected: IndexPath?
330-
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { lastSelected = indexPath }
340+
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
341+
lastSelected = indexPath
342+
}
331343
}
332344

333345
private final class SpySearchDelegate: NSObject, UISearchBarDelegate {

Example/RxSwift-Example/ViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ class ViewController: BaseViewController {
109109

110110
override func setupHCaptcha() {
111111
// swiftlint:disable:next force_try
112-
hcaptcha = try! HCaptcha(apiKey: "00000000-0000-0000-0000-000000000000", locale: locale, diagnosticLog: true, userJourneys: journeySwitch.isOn)
112+
hcaptcha = try! HCaptcha(
113+
apiKey: "00000000-0000-0000-0000-000000000000",
114+
locale: locale,
115+
diagnosticLog: true,
116+
userJourneys: journeySwitch.isOn
117+
)
113118

114119
hcaptcha.configureWebView { [weak self] webview in
115120
webview.frame = self?.view.bounds ?? CGRect.zero

Example/UIKit-Example/ViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ class ViewController: BaseViewController {
5151

5252
override func setupHCaptcha() {
5353
// swiftlint:disable:next force_try
54-
hcaptcha = try! HCaptcha(apiKey: "00000000-0000-0000-0000-000000000000", locale: locale, diagnosticLog: true, userJourneys: journeySwitch.isOn)
54+
hcaptcha = try! HCaptcha(
55+
apiKey: "00000000-0000-0000-0000-000000000000",
56+
locale: locale,
57+
diagnosticLog: true,
58+
userJourneys: journeySwitch.isOn
59+
)
5560

5661
hcaptcha.onEvent { (event, _) in
5762
if event == .open {

HCaptcha-Carthage.xcodeproj/project.pbxproj

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/* Begin PBXBuildFile section */
1010
1F833B7F271DC69C00E4DAB2 /* RxSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F833B7E271DC69C00E4DAB2 /* RxSwift.xcframework */; };
1111
1F833B80271DC69C00E4DAB2 /* RxSwift.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1F833B7E271DC69C00E4DAB2 /* RxSwift.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
12+
43C3B8F62EB973A500705F63 /* HCaptcha_Journeylitics.h in Headers */ = {isa = PBXBuildFile; fileRef = 43C3B8F42EB973A500705F63 /* HCaptcha_Journeylitics.h */; };
13+
43C3B8FA2EBA065F00705F63 /* HCaptchaWebViewManager+JSCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C3B8F72EBA065F00705F63 /* HCaptchaWebViewManager+JSCommand.swift */; };
14+
43C3B8FC2EBA07C900705F63 /* HCaptchaWebViewManager+Private.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C3B8FB2EBA07C900705F63 /* HCaptchaWebViewManager+Private.swift */; };
1215
43DC08142E971586003839A5 /* HCaptchaVerifyParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43DC08132E971586003839A5 /* HCaptchaVerifyParams.swift */; };
1316
43DC08392EA819C2003839A5 /* UISearchBar+JL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43DC082C2EA819C2003839A5 /* UISearchBar+JL.swift */; };
1417
43DC083A2EA819C2003839A5 /* JourneyliticsCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43DC08232EA819C2003839A5 /* JourneyliticsCore.swift */; };
@@ -75,6 +78,9 @@
7578

7679
/* Begin PBXFileReference section */
7780
1F833B7E271DC69C00E4DAB2 /* RxSwift.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = RxSwift.xcframework; path = Carthage/Build/RxSwift.xcframework; sourceTree = "<group>"; };
81+
43C3B8F42EB973A500705F63 /* HCaptcha_Journeylitics.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HCaptcha_Journeylitics.h; sourceTree = "<group>"; };
82+
43C3B8F72EBA065F00705F63 /* HCaptchaWebViewManager+JSCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HCaptchaWebViewManager+JSCommand.swift"; sourceTree = "<group>"; };
83+
43C3B8FB2EBA07C900705F63 /* HCaptchaWebViewManager+Private.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HCaptchaWebViewManager+Private.swift"; sourceTree = "<group>"; };
7884
43DC08132E971586003839A5 /* HCaptchaVerifyParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HCaptchaVerifyParams.swift; sourceTree = "<group>"; };
7985
43DC081A2EA8199F003839A5 /* HCaptcha_Journeylitics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HCaptcha_Journeylitics.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8086
43DC08232EA819C2003839A5 /* JourneyliticsCore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JourneyliticsCore.swift; sourceTree = "<group>"; };
@@ -122,10 +128,6 @@
122128
F2AE8613204F3B41002E28D7 /* HCaptchaResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HCaptchaResult.swift; sourceTree = "<group>"; };
123129
/* End PBXFileReference section */
124130

125-
/* Begin PBXFileSystemSynchronizedRootGroup section */
126-
43DC081B2EA8199F003839A5 /* HCaptcha_Journeylitics */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = HCaptcha_Journeylitics; sourceTree = "<group>"; };
127-
/* End PBXFileSystemSynchronizedRootGroup section */
128-
129131
/* Begin PBXFrameworksBuildPhase section */
130132
43DC08172EA8199F003839A5 /* Frameworks */ = {
131133
isa = PBXFrameworksBuildPhase;
@@ -152,6 +154,14 @@
152154
/* End PBXFrameworksBuildPhase section */
153155

154156
/* Begin PBXGroup section */
157+
43C3B8F52EB973A500705F63 /* HCaptcha_Journeylitics */ = {
158+
isa = PBXGroup;
159+
children = (
160+
43C3B8F42EB973A500705F63 /* HCaptcha_Journeylitics.h */,
161+
);
162+
path = HCaptcha_Journeylitics;
163+
sourceTree = "<group>";
164+
};
155165
43DC08252EA819C2003839A5 /* Core */ = {
156166
isa = PBXGroup;
157167
children = (
@@ -215,7 +225,7 @@
215225
F206BACF1F8D3E2800A25807 /* Cartfile */,
216226
F206BAB21F8D3DE900A25807 /* HCaptcha-Carthage */,
217227
F206BB1A1F8D4DBC00A25807 /* HCaptcha_RxSwift */,
218-
43DC081B2EA8199F003839A5 /* HCaptcha_Journeylitics */,
228+
43C3B8F52EB973A500705F63 /* HCaptcha_Journeylitics */,
219229
F206BAB11F8D3DE900A25807 /* Products */,
220230
F206BAD11F8D3E7600A25807 /* Frameworks */,
221231
F24EA1D41F967F21001DEC17 /* Recovered References */,
@@ -287,6 +297,8 @@
287297
E6DB9EA727B15954008F0327 /* HCaptchaDebugInfo.swift */,
288298
43DC08132E971586003839A5 /* HCaptchaVerifyParams.swift */,
289299
F24EA1D91F9683F5001DEC17 /* HCaptchaWebViewManager.swift */,
300+
43C3B8F72EBA065F00705F63 /* HCaptchaWebViewManager+JSCommand.swift */,
301+
43C3B8FB2EBA07C900705F63 /* HCaptchaWebViewManager+Private.swift */,
290302
E614B37A2BCEBF3400CEA791 /* HCaptchaWebViewManager+WKNavigationDelegate.swift */,
291303
F24EA1DA1F9683F5001DEC17 /* String+Dict.swift */,
292304
F24EA1DB1F9683F5001DEC17 /* HCaptchaError.swift */,
@@ -316,6 +328,7 @@
316328
isa = PBXHeadersBuildPhase;
317329
buildActionMask = 2147483647;
318330
files = (
331+
43C3B8F62EB973A500705F63 /* HCaptcha_Journeylitics.h in Headers */,
319332
);
320333
runOnlyForDeploymentPostprocessing = 0;
321334
};
@@ -351,9 +364,6 @@
351364
);
352365
dependencies = (
353366
);
354-
fileSystemSynchronizedGroups = (
355-
43DC081B2EA8199F003839A5 /* HCaptcha_Journeylitics */,
356-
);
357367
name = HCaptcha_Journeylitics;
358368
packageProductDependencies = (
359369
);
@@ -423,7 +433,7 @@
423433
};
424434
};
425435
buildConfigurationList = F206BAAA1F8D3DE900A25807 /* Build configuration list for PBXProject "HCaptcha-Carthage" */;
426-
compatibilityVersion = "Xcode 3.2";
436+
compatibilityVersion = "Xcode 12.0";
427437
developmentRegion = English;
428438
hasScannedForEncodings = 0;
429439
knownRegions = (
@@ -499,6 +509,7 @@
499509
files = (
500510
E6BF595C288AE915007CE1CE /* HCaptchaHtml.swift in Sources */,
501511
E634944A2828856300130AC5 /* HCaptchaEvent.swift in Sources */,
512+
43C3B8FA2EBA065F00705F63 /* HCaptchaWebViewManager+JSCommand.swift in Sources */,
502513
E65C08A02A656CC6002E82EC /* HCaptchaLog.swift in Sources */,
503514
F24EA1E51F968403001DEC17 /* HCaptchaError.swift in Sources */,
504515
E65145E327786BDB0079668A /* HCaptchaConfig.swift in Sources */,
@@ -511,6 +522,7 @@
511522
F231B39A1FEC51C800F82943 /* DispatchQueue+Throttle.swift in Sources */,
512523
43DC084C2EA819DB003839A5 /* HCaptchaJourneys.swift in Sources */,
513524
E6DB9EA827B15954008F0327 /* HCaptchaDebugInfo.swift in Sources */,
525+
43C3B8FC2EBA07C900705F63 /* HCaptchaWebViewManager+Private.swift in Sources */,
514526
E614B37B2BCEBF3400CEA791 /* HCaptchaWebViewManager+WKNavigationDelegate.swift in Sources */,
515527
E683772129053E560021BFD7 /* HCaptchaURLOpener.swift in Sources */,
516528
);

HCaptcha/Classes/HCaptchaJourneys.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum HCaptchaJourneys {
3333
}
3434
return anyObj
3535
}
36-
36+
3737
/// Returns collected events as a JSON string ("[]" when unavailable/empty).
3838
/// @deprecated Use drainEvents() instead for better performance
3939
public static func drainEventsAsJSONString() -> String {

HCaptcha/Classes/HCaptchaVerifyParams.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public class HCaptchaVerifyParams: NSObject {
5252
*/
5353
@objc
5454
internal init(phonePrefix: String?,
55-
phoneNumber: String?,
56-
rqdata: String?,
57-
userJourneys: Any?,
58-
resetOnErr: Bool) {
55+
phoneNumber: String?,
56+
rqdata: String?,
57+
userJourneys: Any?,
58+
resetOnErr: Bool) {
5959
self.phonePrefix = phonePrefix
6060
self.phoneNumber = phoneNumber
6161
self.rqdata = rqdata
@@ -64,11 +64,17 @@ public class HCaptchaVerifyParams: NSObject {
6464
}
6565

6666
internal convenience init(phonePrefix: String? = nil,
67-
phoneNumber: String? = nil,
68-
rqdata: String? = nil,
69-
userJourneys: Any? = nil,
70-
resetOnError: Bool = true) {
71-
self.init(phonePrefix: phonePrefix, phoneNumber: phoneNumber, rqdata: rqdata, userJourneys: userJourneys, resetOnErr: resetOnError)
67+
phoneNumber: String? = nil,
68+
rqdata: String? = nil,
69+
userJourneys: Any? = nil,
70+
resetOnError: Bool = true) {
71+
self.init(
72+
phonePrefix: phonePrefix,
73+
phoneNumber: phoneNumber,
74+
rqdata: rqdata,
75+
userJourneys: userJourneys,
76+
resetOnErr: resetOnError
77+
)
7278
}
7379

7480
/**
@@ -78,7 +84,13 @@ public class HCaptchaVerifyParams: NSObject {
7884
phoneNumber: String? = nil,
7985
rqdata: String? = nil,
8086
resetOnError: Bool = true) {
81-
self.init(phonePrefix: phonePrefix, phoneNumber: phoneNumber, rqdata: rqdata, userJourneys: nil, resetOnErr: resetOnError)
87+
self.init(
88+
phonePrefix: phonePrefix,
89+
phoneNumber: phoneNumber,
90+
rqdata: rqdata,
91+
userJourneys: nil,
92+
resetOnErr: resetOnError
93+
)
8294
}
8395

8496
/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// HCaptchaWebViewManager+JSCommand.swift
3+
// HCaptcha
4+
//
5+
// Copyright © 2025 HCaptcha. All rights reserved.
6+
//
7+
8+
import Foundation
9+
10+
extension HCaptchaWebViewManager {
11+
enum JSCommand: Equatable {
12+
case execute(HCaptchaVerifyParams? = nil)
13+
case reset
14+
15+
var rawValue: String {
16+
switch self {
17+
case .execute(let verifyParams):
18+
if let verifyParams = verifyParams, let jsonString = verifyParams.toJSONString() {
19+
return "execute(\(jsonString));"
20+
} else {
21+
return "execute();"
22+
}
23+
case .reset:
24+
return "reset();"
25+
}
26+
}
27+
28+
static func == (lhs: JSCommand, rhs: JSCommand) -> Bool {
29+
if case .execute(let lhsParams) = lhs, case .execute(let rhsParams) = rhs {
30+
return lhsParams?.toJSONString() == rhsParams?.toJSONString()
31+
} else {
32+
return lhs.rawValue == rhs.rawValue
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)