iOS: fix in some case application delegate's window is nil

This commit is contained in:
pengfei.zhou 2022-07-13 17:13:09 +08:00 committed by osborn
parent 1a3789fc4c
commit 9cb4764bfd

View File

@ -126,7 +126,12 @@ void ShowToastInVC(UIViewController *_Nonnull vc, NSString *_Nonnull text, Doric
BOOL hasNotch() { BOOL hasNotch() {
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
CGFloat height = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom; CGFloat height;
if ([[UIApplication sharedApplication] delegate].window) {
height = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;
} else {
height = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
}
return (height > 0); return (height > 0);
} else { } else {
return NO; return NO;