diff --git a/React/CoreModules/RCTAlertController.m b/React/CoreModules/RCTAlertController.m index 02636c3f4a7b8f..06f8fc2ac8e2d9 100644 --- a/React/CoreModules/RCTAlertController.m +++ b/React/CoreModules/RCTAlertController.m @@ -20,10 +20,17 @@ @implementation RCTAlertController - (UIWindow *)alertWindow { if (_alertWindow == nil) { - _alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds]; + UIWindow *keyWindow = RCTSharedApplication().keyWindow; + if (keyWindow) { + _alertWindow = [[UIWindow alloc] initWithFrame:keyWindow.bounds]; _alertWindow.rootViewController = [UIViewController new]; _alertWindow.windowLevel = UIWindowLevelAlert + 1; + } else { + // keyWindow is nil, so we cannot create and initialize _alertWindow + NSLog(@"Unable to create alert window: keyWindow is nil"); } +} + return _alertWindow; }