Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Avoid crashing the app if the app delegate is written in Swift and do…
Browse files Browse the repository at this point in the history
…esn'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
  • Loading branch information
Xavier Jurado Cristobal authored and facebook-github-bot committed Nov 8, 2024
1 parent e160f54 commit 2e30968
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2e30968

Please sign in to comment.