Skip to content

Commit f4b722b

Browse files
authored
Implement userAgent for Data Connect (#8)
1 parent ebf8538 commit f4b722b

File tree

5 files changed

+100
-4
lines changed

5 files changed

+100
-4
lines changed

.github/workflows/spm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
target: [iOS, tvOS, macOS, catalyst, visionOS]
3434
xcode: [Xcode_15.2, Xcode_15.4, Xcode_16_Release_Candidate]
3535
runs-on: ${{ matrix.os }}
36+
env:
37+
FIREBASE_MAIN: 1
3638
steps:
3739
- uses: actions/checkout@v4
3840
- name: Xcode

Package.swift

Lines changed: 15 additions & 4 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)],
@@ -31,8 +29,7 @@ let package = Package(
3129
),
3230
],
3331
dependencies: [
34-
.package(url: "https://github.com/firebase/firebase-ios-sdk",
35-
from: "11.0.0"),
32+
firebaseDependency(),
3633
.package(
3734
url: "https://github.com/grpc/grpc-swift.git",
3835
from: "1.19.1" // TODO: Constrain to a range at time of release
@@ -43,6 +40,8 @@ let package = Package(
4340
name: "FirebaseDataConnect",
4441
dependencies: [
4542
.product(name: "GRPC", package: "grpc-swift"),
43+
.product(name: "FirebaseCore", package: "firebase-ios-sdk"),
44+
// TODO: Investigate switching Auth and AppCheck to interop.
4645
.product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
4746
.product(name: "FirebaseAppCheck", package: "firebase-ios-sdk"),
4847

@@ -56,3 +55,15 @@ let package = Package(
5655
),
5756
]
5857
)
58+
59+
func firebaseDependency() -> Package.Dependency {
60+
let firebaseURL = "https://github.com/firebase/firebase-ios-sdk"
61+
62+
// Point SPM CI to the tip of main of https://github.com/firebase/firebase-ios-sdk so that the
63+
// release process can defer publishing the GoogleAppMeasurement tag until after testing.
64+
if ProcessInfo.processInfo.environment["FIREBASE_MAIN"] != nil {
65+
return .package(url: firebaseURL, branch: "main")
66+
}
67+
68+
return .package(url: firebaseURL, exact: "11.3.0")
69+
}

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 Version.version
22+
}
23+
}

Sources/Internal/Version.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
18+
struct Version {
19+
static let version = "11.3.0-beta"
20+
}

Tests/Unit/UserAgentTests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 options: FirebaseOptions = {
23+
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
24+
gcmSenderID: "00000000000000000-00000000000-000000000")
25+
options.projectID = "user-agent-test"
26+
options.apiKey = "testUserAgentDummyApiKey"
27+
return options
28+
}()
29+
30+
override class func setUp() {
31+
FirebaseApp.configure(name: "user-agent", options: options)
32+
}
33+
34+
/// Confirm that Data Connect gets added to the user agent.
35+
func testUserAgent() {
36+
let userAgent = FirebaseApp.firebaseUserAgent()
37+
let version = Version.version
38+
XCTAssertTrue(userAgent.contains("fire-dc/\(version)"))
39+
}
40+
}

0 commit comments

Comments
 (0)