Skip to content

Commit 934a23f

Browse files
committed
Implement userAgent for Data Connect
1 parent 52e39a8 commit 934a23f

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

Package.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import class Foundation.ProcessInfo
2020
import PackageDescription
2121

22-
// let firebaseVersion = "10.25.0"
23-
2422
let package = Package(
2523
name: "FirebaseDataConnect",
2624
platforms: [.iOS(.v12), .macCatalyst(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v7)],
@@ -32,7 +30,7 @@ let package = Package(
3230
],
3331
dependencies: [
3432
.package(url: "https://github.com/firebase/firebase-ios-sdk",
35-
from: "11.0.0"),
33+
branch: "nc/demo-reg"),
3634
.package(
3735
url: "https://github.com/grpc/grpc-swift.git",
3836
from: "1.19.1" // TODO: Constrain to a range at time of release

Sources/DataConnectSettings.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Foundation
1616

1717
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1818
public struct DataConnectSettings: Hashable, Equatable {
19+
static let version = "11.3.0-beta"
1920
public private(set) var host: String
2021
public private(set) var port: Int
2122
public private(set) var sslEnabled: Bool

Sources/Internal/Component.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// Class for registration with the Firebase component system, including userAgent functionality.
18+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
19+
@objc(FIRDataConnectComponent) class DataConnectComponent: NSObject {
20+
@objc class func sdkVersion() -> String {
21+
return DataConnectSettings.version
22+
}
23+
}

Tests/Unit/UserAgentTests.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
import XCTest
17+
18+
import FirebaseCore
19+
@testable import FirebaseDataConnect
20+
21+
final class UserAgentTests: XCTestCase {
22+
static var defaultApp: FirebaseApp?
23+
24+
static var options: FirebaseOptions = {
25+
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
26+
gcmSenderID: "00000000000000000-00000000000-000000000")
27+
options.projectID = "fdc-test"
28+
options.apiKey = "testDummyApiKey"
29+
return options
30+
}()
31+
32+
override class func setUp() {
33+
FirebaseApp.configure(options: options)
34+
defaultApp = FirebaseApp.app()
35+
}
36+
37+
/// Confirm that Data Connect gets added to the user agent.
38+
func testUserAgent() {
39+
let userAgent = FirebaseApp.firebaseUserAgent()
40+
let version = DataConnectSettings.version
41+
XCTAssertTrue(userAgent.contains("fire-dc/\(version)"))
42+
}
43+
}

0 commit comments

Comments
 (0)