From 094c0c40d8e398a565829ae6914569d6095d4ed3 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 11 Jul 2023 16:30:34 +0300 Subject: [PATCH] build: prevent compile-time failure in application extensions --- .../Extensions/UIViewController+FixedTopOffet.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/TIUIElements/Sources/Helpers/Extensions/UIViewController+FixedTopOffet.swift b/TIUIElements/Sources/Helpers/Extensions/UIViewController+FixedTopOffet.swift index a370590b..bf1c3de1 100644 --- a/TIUIElements/Sources/Helpers/Extensions/UIViewController+FixedTopOffet.swift +++ b/TIUIElements/Sources/Helpers/Extensions/UIViewController+FixedTopOffet.swift @@ -11,7 +11,16 @@ public extension UIViewController { if #available(iOS 13.0, *) { statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0 } else { - statusBarHeight = UIApplication.shared.statusBarFrame.height + // prevent compile-time failure: 'shared' is unavailable in application extensions for iOS + + let sharedSelector = Selector(("shared")) + + if UIApplication.responds(to: sharedSelector), + let sharedApplication = UIApplication.perform(sharedSelector).takeRetainedValue() as? UIApplication { + statusBarHeight = sharedApplication.statusBarFrame.height + } else { // application extension, statusBarFrame is not applicable + statusBarHeight = .zero + } } let navigationBarHeight = navigationBar?.bounds.height ?? 0