Skip to content

Commit 20ab31f

Browse files
maksymmalyhinpaulb777
authored andcommitted
Scene delegate swizzling: don't crash when there is UIScene.delegate == nil (#4498) (#4499)
1 parent a99f969 commit 20ab31f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

GoogleUtilities/AppDelegateSwizzler/GULAppDelegateSwizzler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ + (void)proxySceneDelegateIfNeeded:(UIScene *)scene {
10691069

10701070
// Skip proxying if the class has a prefix of kGULAppDelegatePrefix, which means it has been
10711071
// proxied before.
1072-
if ([className hasPrefix:kGULAppDelegatePrefix]) {
1072+
if (className == nil || [className hasPrefix:kGULAppDelegatePrefix]) {
10731073
return;
10741074
}
10751075

GoogleUtilities/Example/Tests/Swizzler/GULAppDelegateSwizzlerTest.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,14 @@ - (void)testAppDelegateIsProxiedIncludingAPNSMethodsWhenEnabled {
13191319

13201320
#if ((TARGET_OS_IOS || TARGET_OS_TV) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000))
13211321

1322+
- (void)testProxySceneDelegateWithNoSceneDelegate {
1323+
if (@available(iOS 13, tvOS 13, *)) {
1324+
id mockSharedScene = OCMClassMock([UIScene class]);
1325+
OCMStub([mockSharedScene delegate]).andReturn(nil);
1326+
XCTAssertNoThrow([GULAppDelegateSwizzler proxySceneDelegateIfNeeded:mockSharedScene]);
1327+
}
1328+
}
1329+
13221330
- (void)testProxySceneDelegate {
13231331
if (@available(iOS 13, tvOS 13, *)) {
13241332
GULTestSceneDelegate *realSceneDelegate = [[GULTestSceneDelegate alloc] init];

0 commit comments

Comments
 (0)