diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b5894..1e6a7e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Unreleased +- [fixed] On visionOS, `GULAppEnvironmentUtil`'s `isAppExtension` (and so + `supportsBackgroundURLSessionUploads`) and, on devices, `isFromAppStore` + could return wrong results. Their platform checks covered iOS, tvOS, watchOS + and macOS but not visionOS, so the code ended without returning a value. For + example, an app could be treated as an app extension, which skips App + Delegate swizzling. visionOS now uses the same checks as iOS. - [fixed] The App Delegate proxy now works when it is requested before the app has an App Delegate, such as when a SwiftUI app calls `FirebaseApp.configure()` in its `App` initializer. Proxying now waits until diff --git a/GoogleUtilities/Environment/GULAppEnvironmentUtil.m b/GoogleUtilities/Environment/GULAppEnvironmentUtil.m index 2dc077f..258726c 100644 --- a/GoogleUtilities/Environment/GULAppEnvironmentUtil.m +++ b/GoogleUtilities/Environment/GULAppEnvironmentUtil.m @@ -47,20 +47,20 @@ + (void)setProcessInfoForTest:(NSProcessInfo *)processInfo { static NSString *const kFIRAIdentitySandboxReceiptFileName = @"sandboxReceipt"; static BOOL HasSCInfoFolder(void) { -#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH +#if TARGET_OS_OSX + return NO; +#else NSString *bundlePath = [NSBundle mainBundle].bundlePath; NSString *scInfoPath = [bundlePath stringByAppendingPathComponent:@"SC_Info"]; return [[NSFileManager defaultManager] fileExistsAtPath:scInfoPath]; -#elif TARGET_OS_OSX - return NO; #endif } static BOOL HasEmbeddedMobileProvision(void) { -#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH - return [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"].length > 0; -#elif TARGET_OS_OSX +#if TARGET_OS_OSX return NO; +#else + return [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"].length > 0; #endif } @@ -239,12 +239,12 @@ + (NSString *)systemVersion { } + (BOOL)isAppExtension { -#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH +#if TARGET_OS_OSX + return NO; +#else // Documented by Apple BOOL appExtension = [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"]; return appExtension; -#elif TARGET_OS_OSX - return NO; #endif } diff --git a/GoogleUtilities/Tests/Unit/Environment/GULAppEnvironmentUtilTest.m b/GoogleUtilities/Tests/Unit/Environment/GULAppEnvironmentUtilTest.m index f49395e..3897dba 100644 --- a/GoogleUtilities/Tests/Unit/Environment/GULAppEnvironmentUtilTest.m +++ b/GoogleUtilities/Tests/Unit/Environment/GULAppEnvironmentUtilTest.m @@ -192,4 +192,28 @@ - (void)testAppStoreReceiptURLIsReadOnlyOnce { XCTAssertEqual(receiptURLReadCount, 0); } +- (void)testIsAppExtension { + // The test runner isn't an app extension. + XCTAssertFalse([GULAppEnvironmentUtil isAppExtension]); +} + +- (void)testIsAppExtensionInAppExtensionBundle { + [GULSwizzler swizzleClass:[NSBundle class] + selector:@selector(bundlePath) + isClassSelector:NO + withBlock:^NSString *(id bundle) { + return @"/private/var/containers/Bundle/Application/App.app/PlugIns/" + @"Extension.appex"; + }]; + BOOL isAppExtension = [GULAppEnvironmentUtil isAppExtension]; + [GULSwizzler unswizzleClass:[NSBundle class] selector:@selector(bundlePath) isClassSelector:NO]; + +#if TARGET_OS_OSX + XCTAssertFalse(isAppExtension); +#else + // This includes visionOS, where `isAppExtension` used to end without returning a value. + XCTAssertTrue(isAppExtension); +#endif // TARGET_OS_OSX +} + @end