From 2e309688620e35384094a84dfa8a497637586dc5 Mon Sep 17 00:00:00 2001 From: Xavier Jurado Cristobal Date: Fri, 8 Nov 2024 09:39:18 -0800 Subject: [PATCH] Avoid crashing the app if the app delegate is written in Swift and doesn't have a window property Summary: `window` is an optional property. If an `UIApplicationDelegate` is implemented in Swift and doesn't implement this property, the current code will crash. This was the case for NativeUIPreview's app delegate (used for [iOS Snapshot Test Previews](https://fb.workplace.com/groups/735885229793428/posts/25216903081264969/)): https://www.internalfb.com/code/fbsource/[e59804301a3c]/fbobjc/Configurations/Buck/NativeUIPreview/AppDelegate.swift?lines=6-10 This diff fixes the crash itself, although we may want to do think about a better way to get the size of the window (eg: using `UIWindowSceneDelegate` instead?). Reviewed By: LukeDefeo Differential Revision: D65665540 fbshipit-source-id: 481c76a934d07d2cdc632dbedae6fbabee3c4a9a --- .../FlipperKitUIDebuggerPlugin/Utilities/UIDSnapshot.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Utilities/UIDSnapshot.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Utilities/UIDSnapshot.m index c2806ebd8b4..16211936614 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Utilities/UIDSnapshot.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Utilities/UIDSnapshot.m @@ -31,7 +31,7 @@ // like in Split View on an iPad, the running application is // not using the entire screen thus the snapshot stretches to // fill the screen size which is incorrect. - if (application.delegate.window) { + if ([application.delegate respondsToSelector:@selector(window)]) { size = application.delegate.window.bounds.size; }