From 3829e9b94ca51b54548b91edc61e3d25927a273d Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Mon, 4 Mar 2024 18:41:42 -0800 Subject: [PATCH] Fix access to UIWindow when delegate doesn't implement that property --- .../ORKNormalizedReactionTimeContentView.m | 7 ++++++- ResearchKit/ActiveTasks/ORKStroopContentView.m | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m b/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m index 5fd102db3..c88f96a67 100644 --- a/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m +++ b/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m @@ -78,7 +78,12 @@ - (void)resetAfterDelay:(NSTimeInterval)delay completion:(nullable void (^)(void } -(void)resizeConstraints { - ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + ORKScreenType screenType; + if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)]) { + screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + } else { + screenType = ORKGetVerticalScreenTypeForWindow(NULL); + } if (screenType == ORKScreenTypeiPhone5 ) { NormalizeButtonSize = 70.0; BackgroundViewSpaceMultiplier = 1.75; diff --git a/ResearchKit/ActiveTasks/ORKStroopContentView.m b/ResearchKit/ActiveTasks/ORKStroopContentView.m index 291376592..92c36906e 100644 --- a/ResearchKit/ActiveTasks/ORKStroopContentView.m +++ b/ResearchKit/ActiveTasks/ORKStroopContentView.m @@ -62,8 +62,13 @@ - (instancetype)initWithFrame:(CGRect)frame { [_colorLabel setFont:[UIFont systemFontOfSize:60]]; [_colorLabel setAdjustsFontSizeToFitWidth:YES]; - ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); - + ORKScreenType screenType; + if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)]) { + screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + } else { + screenType = ORKGetVerticalScreenTypeForWindow(NULL); + } + if (screenType == ORKScreenTypeiPhone5 ) { labelWidth = 200.0; labelHeight = 200.0; @@ -145,8 +150,13 @@ -(void)setupGridButtons { _buttonStackView.axis = UILayoutConstraintAxisVertical; - ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); - + ORKScreenType screenType; + if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)]) { + screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + } else { + screenType = ORKGetVerticalScreenTypeForWindow(NULL); + } + if (screenType == ORKScreenTypeiPhone6) { minimumButtonHeight = 150.0; } else if (screenType == ORKScreenTypeiPhone5 ) {