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
24 changes: 24 additions & 0 deletions FirebaseCore/Sources/FIRApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
NSString *const kFIRAppDiagnosticsFIRAppKey = @"FIRApp";
NSString *const kFIRAppDiagnosticsSDKNameKey = @"SDKName";
NSString *const kFIRAppDiagnosticsSDKVersionKey = @"SDKVersion";
NSString *const kFIRAppDiagnosticsApplePlatformPrefix = @"apple-platform";

// Auth internal notification notification and key.
NSString *const FIRAuthStateDidChangeInternalNotification =
Expand Down Expand Up @@ -579,6 +580,9 @@ + (NSString *)firebaseUserAgent {

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

[FIRApp registerLibrary:kFIRAppDiagnosticsApplePlatformPrefix
withVersion:[self applePlatform]];
});

NSMutableArray<NSString *> *libraries =
Expand Down Expand Up @@ -606,6 +610,26 @@ + (BOOL)hasSwiftRuntime {
return hasSwiftRuntime;
}

+ (NSString *)applePlatform {
NSString *applePlatform = @"unknown";

// When a Catalyst app is run on macOS then both `TARGET_OS_MACCATALYST` and `TARGET_OS_IOS` are
// `true`, which means the condition list is order-sensitive.
#if TARGET_OS_MACCATALYST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment summarizing the discussion so we remember this is order-sensitive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comment. Is it what you meant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Thanks!

applePlatform = @"maccatalyst";
#elif TARGET_OS_IOS
applePlatform = @"ios";
#elif TARGET_OS_TV
applePlatform = @"tvos";
#elif TARGET_OS_OSX
applePlatform = @"macos";
#elif TARGET_OS_WATCH
applePlatform = @"watchos";
#endif

return applePlatform;
}

- (void)checkExpectedBundleID {
NSArray *bundles = [FIRBundleUtil relevantBundles];
NSString *expectedBundleID = [self expectedBundleID];
Expand Down
42 changes: 42 additions & 0 deletions FirebaseCore/Tests/Unit/FIRAppTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,48 @@ - (void)testSwiftFlagWithNoSwift {
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"swift/false"]);
}

- (void)testApplePlatformFlag {
// When a Catalyst app is run on macOS then both `TARGET_OS_MACCATALYST` and `TARGET_OS_IOS` are
// `true`.
#if TARGET_OS_MACCATALYST
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/ios"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/tvos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/macos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/watchos"]);
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"apple-platform/maccatalyst"]);
#elif TARGET_OS_IOS
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"apple-platform/ios"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/tvos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/macos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/watchos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/maccatalyst"]);
#endif // TARGET_OS_MACCATALYST

#if TARGET_OS_TV
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/ios"]);
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"apple-platform/tvos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/macos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/watchos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/maccatalyst"]);
#endif // TARGET_OS_TV

#if TARGET_OS_OSX
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/ios"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/tvos"]);
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"apple-platform/macos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/watchos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/maccatalyst"]);
#endif // TARGET_OS_OSX

#if TARGET_OS_WATCH
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/ios"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/tvos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/macos"]);
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"apple-platform/watchos"]);
XCTAssertFalse([[FIRApp firebaseUserAgent] containsString:@"apple-platform/maccatalyst"]);
#endif // TARGET_OS_WATCH
}

#pragma mark - Core Diagnostics

- (void)testCoreDiagnosticsLoggedWhenFIRAppIsConfigured {
Expand Down