File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Sources/SnapshotTesting/Common Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -664,6 +664,18 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate {
664664#endif
665665
666666#if os(iOS) || os(tvOS)
667+ extension UIApplication {
668+ static var sharedIfAvailable : UIApplication ? {
669+ let sharedSelector = NSSelectorFromString ( " shared " )
670+ guard UIApplication . responds ( to: sharedSelector) else {
671+ return nil
672+ }
673+
674+ let shared = UIApplication . perform ( sharedSelector)
675+ return shared? . takeUnretainedValue ( ) as! UIApplication ?
676+ }
677+ }
678+
667679func prepareView(
668680 config: ViewImageConfig ,
669681 drawHierarchyInKeyWindow: Bool ,
@@ -680,7 +692,7 @@ func prepareView(
680692 let traits = UITraitCollection ( traitsFrom: [ config. traits, traits] )
681693 let window : UIWindow
682694 if drawHierarchyInKeyWindow {
683- guard let keyWindow = UIApplication . shared . keyWindow else {
695+ guard let keyWindow = UIApplication . sharedIfAvailable ? . keyWindow else {
684696 fatalError ( " 'drawHierarchyInKeyWindow' requires tests to be run in a host application " )
685697 }
686698 window = keyWindow
You can’t perform that action at this time.
0 commit comments