Skip to content

Commit

Permalink
[Environment] Calling '+[GULAppEnvironmentUtil applePlatform]' return…
Browse files Browse the repository at this point in the history
…s visionOS specific value (#113)
  • Loading branch information
ncooke3 authored Jun 28, 2023
1 parent 0a24867 commit 58d03d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 7.11.3 (SwiftPM Only)
- Calling `+[GULAppEnvironmentUtil applePlatform]` now returns 'visionos' when
running on visionOS.

# 7.11.2 (SwiftPM Only)
- Fix build errors on the visionOS platform. (#108)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
/// @return YES if Swift runtime detected in the app.
+ (BOOL)hasSwiftRuntime __deprecated;

/// @return An Apple platform. Possible values "ios", "tvos", "macos", "watchos", "maccatalyst".
/// @return An Apple platform. Possible values "ios", "tvos", "macos", "watchos", "maccatalyst", and
/// "visionos".
+ (NSString *)applePlatform;

/// @return An Apple Device platform. Same possible values as `applePlatform`, with the addition of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ + (NSString *)applePlatform {
// `true`, which means the condition list is order-sensitive.
#if TARGET_OS_MACCATALYST
applePlatform = @"maccatalyst";
#elif TARGET_OS_IOS
#elif TARGET_OS_IOS && (!defined(TARGET_OS_XR) || !TARGET_OS_XR)
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
if (@available(iOS 14.0, *)) {
// Early iOS 14 betas do not include isiOSAppOnMac (#6969)
Expand All @@ -353,6 +353,8 @@ + (NSString *)applePlatform {
applePlatform = @"macos";
#elif TARGET_OS_WATCH
applePlatform = @"watchos";
#elif defined(TARGET_OS_XR) && TARGET_OS_XR
applePlatform = @"visionos";
#endif // TARGET_OS_MACCATALYST

return applePlatform;
Expand Down
12 changes: 10 additions & 2 deletions GoogleUtilities/Tests/Unit/Environment/GULAppEnvironmentUtilTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (void)testApplePlatform {
// `true`.
#if TARGET_OS_MACCATALYST
NSString *expectedPlatform = @"maccatalyst";
#elif TARGET_OS_IOS
#elif TARGET_OS_IOS && (!defined(TARGET_OS_XR) || !TARGET_OS_XR)
NSString *expectedPlatform = @"ios";
#endif // TARGET_OS_MACCATALYST

Expand All @@ -100,6 +100,10 @@ - (void)testApplePlatform {
NSString *expectedPlatform = @"watchos";
#endif // TARGET_OS_WATCH

#if defined(TARGET_OS_XR) && TARGET_OS_XR
NSString *expectedPlatform = @"visionos";
#endif // defined(TARGET_OS_XR) && TARGET_OS_XR

XCTAssertEqualObjects([GULAppEnvironmentUtil applePlatform], expectedPlatform);
}

Expand All @@ -108,7 +112,7 @@ - (void)testAppleDevicePlatform {
// `true`.
#if TARGET_OS_MACCATALYST
NSString *expectedPlatform = @"maccatalyst";
#elif TARGET_OS_IOS
#elif TARGET_OS_IOS && (!defined(TARGET_OS_XR) || !TARGET_OS_XR)
NSString *expectedPlatform = @"ios";

if ([[UIDevice currentDevice].model.lowercaseString containsString:@"ipad"] ||
Expand All @@ -129,6 +133,10 @@ - (void)testAppleDevicePlatform {
NSString *expectedPlatform = @"watchos";
#endif // TARGET_OS_WATCH

#if defined(TARGET_OS_XR) && TARGET_OS_XR
NSString *expectedPlatform = @"visionos";
#endif // defined(TARGET_OS_XR) && TARGET_OS_XR

XCTAssertEqualObjects([GULAppEnvironmentUtil appleDevicePlatform], expectedPlatform);
}

Expand Down

0 comments on commit 58d03d2

Please sign in to comment.