From 62fcb3847bf74bb3d6898dc3bfbe06adbf13ebb0 Mon Sep 17 00:00:00 2001 From: banjun Date: Wed, 20 Sep 2023 21:36:26 +0900 Subject: [PATCH 1/2] fix iOS 17 black screenshot due to calling keyboard window drawViewHierarchyInRect --- Sources/KIF/Additions/UIApplication-KIFAdditions.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/KIF/Additions/UIApplication-KIFAdditions.m b/Sources/KIF/Additions/UIApplication-KIFAdditions.m index cbc3e5fe..bf7ee7f7 100644 --- a/Sources/KIF/Additions/UIApplication-KIFAdditions.m +++ b/Sources/KIF/Additions/UIApplication-KIFAdditions.m @@ -178,7 +178,9 @@ - (BOOL)writeScreenshotForLine:(NSUInteger)lineNumber inFile:(NSString *)filenam } return NO; } - + + UIWindow *keyboardWindow = [self keyboardWindow]; + UIGraphicsBeginImageContextWithOptions([[windows objectAtIndex:0] bounds].size, YES, 0); for (UIWindow *window in windows) { //avoid https://github.com/kif-framework/KIF/issues/679 @@ -186,6 +188,10 @@ - (BOOL)writeScreenshotForLine:(NSUInteger)lineNumber inFile:(NSString *)filenam continue; } + if (window == keyboardWindow) { + continue; + } + if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES]; } else { From da732b55767d1e0cee8bf5f87d3a991b03101d0d Mon Sep 17 00:00:00 2001 From: banjun Date: Wed, 4 Oct 2023 20:58:05 +0900 Subject: [PATCH 2/2] suppress rendering keyboard on screenshot only if runtime is iOS 17+ --- Sources/KIF/Additions/UIApplication-KIFAdditions.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/KIF/Additions/UIApplication-KIFAdditions.m b/Sources/KIF/Additions/UIApplication-KIFAdditions.m index bf7ee7f7..a1bdfc56 100644 --- a/Sources/KIF/Additions/UIApplication-KIFAdditions.m +++ b/Sources/KIF/Additions/UIApplication-KIFAdditions.m @@ -188,8 +188,10 @@ - (BOOL)writeScreenshotForLine:(NSUInteger)lineNumber inFile:(NSString *)filenam continue; } - if (window == keyboardWindow) { - continue; + if (@available(iOS 17.0, *)) { + if (window == keyboardWindow) { + continue; + } } if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {