Skip to content

Commit 97a0dae

Browse files
committed
fixes
1 parent 4b1c052 commit 97a0dae

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
- [ ] 📝 Documentation
2525
- [ ] 🗑️ Chore
2626

27-
## Estimated time to fix the ticket(s) or epic(s) refernced by the PR in days
27+
## Estimated time to fix the ticket(s) or epic(s) referenced by the PR in days
2828

2929
<!--- Add estimate to complete the work -->

FlagsmithClient/Classes/Flagsmith.swift

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,30 @@ public final class Flagsmith: @unchecked Sendable {
2525
/// User-Agent header value for HTTP requests
2626
/// Format: flagsmith-swift-ios-sdk/<version>
2727
/// Falls back to "unknown" if version is not discoverable at runtime
28-
public static var userAgent: String {
28+
public static let userAgent: String {
2929
let version = getSDKVersion()
3030
return "flagsmith-swift-ios-sdk/\(version)"
3131
}
3232

3333
/// Get the SDK version from the bundle at runtime
3434
/// Falls back to hardcoded constant or "unknown" if version is not discoverable
3535
private static func getSDKVersion() -> String {
36-
// Try to get version from the FlagsmithClient bundle first (CocoaPods)
36+
// Try CocoaPods bundle first
3737
if let bundle = Bundle(identifier: "org.cocoapods.FlagsmithClient"),
38-
let version = bundle.infoDictionary?["CFBundleShortVersionString"] as? String,
39-
!version.isEmpty && version != "1.0" {
38+
let version = bundle.infoDictionary?["CFBundleShortVersionString"] as? String,
39+
!version.isEmpty,
40+
version.range(of: #"^\d+\.\d+\.\d+"#, options: .regularExpression) != nil {
4041
return version
4142
}
4243

43-
// Try to get version from the current bundle (for SPM or direct integration)
44-
if let version = Bundle(for: Flagsmith.self).infoDictionary?["CFBundleShortVersionString"] as? String,
45-
!version.isEmpty && version != "1.0" {
44+
// Try SPM bundle
45+
if let version = Bundle(for: Flagsmith.self).infoDictionary?["CFBundleShortVersionString"] as? String,
46+
!version.isEmpty,
47+
version.range(of: #"^\d+\.\d+\.\d+"#, options: .regularExpression) != nil {
4648
return version
4749
}
4850

49-
// Try to get version from the main bundle as last resort (but avoid app versions)
50-
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
51-
!version.isEmpty && version != "1.0" && version.range(of: #"^\d+\.\d+\.\d+$"#, options: NSString.CompareOptions.regularExpression) != nil {
52-
return version
53-
}
54-
55-
// Fallback to hardcoded SDK version constant
56-
return sdkVersionConstant
51+
return "unknown"
5752
}
5853
private let apiManager: APIManager
5954
private let sseManager: SSEManager

FlagsmithClient/Classes/Internal/Router.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ enum Router: Sendable {
100100
if let body = try body(using: encoder) {
101101
request.httpBody = body
102102
}
103-
request.addValue(apiKey, forHTTPHeaderField: "X-Environment-Key")
104-
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
105-
request.addValue(Flagsmith.userAgent, forHTTPHeaderField: "User-Agent")
103+
request.setValue(apiKey, forHTTPHeaderField: "X-Environment-Key")
104+
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
105+
request.setValue(Flagsmith.userAgent, forHTTPHeaderField: "User-Agent")
106106

107107
return request
108108
}

FlagsmithClient/Tests/RouterTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ final class RouterTests: FlagsmithClientTestCase {
3939
let expectedPattern = "^flagsmith-swift-ios-sdk/[0-9]+\\.[0-9]+\\.[0-9]+$"
4040
let regex = try NSRegularExpression(pattern: expectedPattern)
4141
let range = NSRange(location: 0, length: userAgent?.count ?? 0)
42-
XCTAssertTrue(regex.firstMatch(in: userAgent ?? "", options: [], range: range) != nil,
43-
"User-Agent should match pattern 'flagsmith-swift-ios-sdk/<version>', got: \(userAgent ?? "nil")")
42+
let match = regex.firstMatch(in: userAgent ?? "", options: [], range: range)
43+
let message = "User-Agent should match pattern 'flagsmith-swift-ios-sdk/<version>', got: \(userAgent ?? "nil")"
44+
XCTAssertTrue(match != nil, message)
4445
}
4546

4647
func testUserAgentHeaderFormat() {

0 commit comments

Comments
 (0)