Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Example/Core/Tests/FIRAppTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,9 @@ - (void)testInvalidLibraryName {
}

- (void)testInvalidLibraryVersion {
NSString *originalFirebaseUserAgent = [FIRApp firebaseUserAgent];
[FIRApp registerLibrary:@"ValidName" withVersion:@"1.0.0+"];
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:originalFirebaseUserAgent]);
}

- (void)testSingleLibrary {
Expand All @@ -812,6 +813,10 @@ - (void)testRegisteringNonConformingLibrary {
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"InvalidLibrary`/1.0.0"]);
}

- (void)testSwiftFlagWithNoSwift {
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"swift/false"]);
}

#pragma mark - Core Diagnostics

- (void)testCoreDiagnosticsLoggedWhenFIRAppIsConfigured {
Expand Down
22 changes: 22 additions & 0 deletions Example/Core/Tests/Swift/FIRAppTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import XCTest
@testable import FirebaseCore

class FIRAppTests: XCTestCase {
func testSwiftFlagWithSwift() {
XCTAssertTrue(FirebaseApp.firebaseUserAgent().contains("swift"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import "FIRAppInternal.h"
25 changes: 23 additions & 2 deletions Firebase/Core/FIRApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

#import <GoogleUtilities/GULAppEnvironmentUtil.h>

#import <objc/runtime.h>

// The kFIRService strings are only here while transitioning CoreDiagnostics from the Analytics
// pod to a Core dependency. These symbols are not used and should be deleted after the transition.
NSString *const kFIRServiceAdMob;
Expand Down Expand Up @@ -114,6 +116,7 @@ @implementation FIRApp
static NSMutableDictionary *sAllApps;
static FIRApp *sDefaultApp;
static NSMutableDictionary *sLibraryVersions;
static dispatch_once_t sFirebaseUserAgentOnceToken;

+ (void)configure {
FIROptions *options = [FIROptions defaultOptions];
Expand Down Expand Up @@ -275,6 +278,7 @@ + (void)resetApps {
sAllApps = nil;
[sLibraryVersions removeAllObjects];
sLibraryVersions = nil;
sFirebaseUserAgentOnceToken = 0;
}
}

Expand Down Expand Up @@ -556,8 +560,7 @@ + (void)registerInternalLibrary:(nonnull Class<FIRLibrary>)library

+ (NSString *)firebaseUserAgent {
@synchronized(self) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_once(&sFirebaseUserAgentOnceToken, ^{
// Report FirebaseCore version for useragent string
[FIRApp registerLibrary:@"fire-ios"
withVersion:[NSString stringWithUTF8String:FIRCoreVersionString]];
Expand All @@ -571,7 +574,11 @@ + (NSString *)firebaseUserAgent {
if (sdkVersion) {
[FIRApp registerLibrary:@"apple-sdk" withVersion:sdkVersion];
}

NSString *swiftFlagValue = [self hasSwiftRuntime] ? @"true" : @"false";
[FIRApp registerLibrary:@"swift" withVersion:swiftFlagValue];
});

NSMutableArray<NSString *> *libraries =
[[NSMutableArray<NSString *> alloc] initWithCapacity:sLibraryVersions.count];
for (NSString *libraryName in sLibraryVersions) {
Expand All @@ -583,6 +590,20 @@ + (NSString *)firebaseUserAgent {
}
}

+ (BOOL)hasSwiftRuntime {
// The class
// [Swift._SwiftObject](https://github.com/apple/swift/blob/5eac3e2818eb340b11232aff83edfbd1c307fa03/stdlib/public/runtime/SwiftObject.h#L35)
// is a part of Swift runtime, so it should be present if Swift runtime is available.

BOOL hasSwiftRuntime =
objc_lookUpClass("Swift._SwiftObject") != nil ||
// Swift object class name before
// https://github.com/apple/swift/commit/9637b4a6e11ddca72f5f6dbe528efc7c92f14d01
objc_getClass("_TtCs12_SwiftObject") != nil;

return hasSwiftRuntime;
}

- (void)checkExpectedBundleID {
NSArray *bundles = [FIRBundleUtil relevantBundles];
NSString *expectedBundleID = [self expectedBundleID];
Expand Down
8 changes: 8 additions & 0 deletions FirebaseCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration
unit_tests.dependency 'OCMock'
unit_tests.resources = 'Example/Core/App/GoogleService-Info.plist'
end

s.test_spec 'swift-unit' do |swift_unit_tests|
swift_unit_tests.source_files = 'Example/Core/Tests/Swift/**/*.swift',
'Example/Core/Tests/Swift/**/*.h'
swift_unit_tests.pod_target_xcconfig = {
'SWIFT_OBJC_BRIDGING_HEADER' => '$(PODS_TARGET_SRCROOT)/Example/Core/Tests/Swift/FirebaseCore-iOS-Unit-swift-unit-Bridging-Header.h'
}
end
end