Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions GoogleUtilities/Environment/GULAppEnvironmentUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 <a href="https://goo.gl/RRB2Up">Apple</a>
BOOL appExtension = [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"];
return appExtension;
#elif TARGET_OS_OSX
return NO;
#endif
}

Expand Down
24 changes: 24 additions & 0 deletions GoogleUtilities/Tests/Unit/Environment/GULAppEnvironmentUtilTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading