danielsaidi / Sheeeeeeeeet

Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UIApplication.shared.keyWindow is unavailable (Xcode 13 Beta3 / iOS 15)

apps4everyone opened this issue · comments

UIApplication.shared.keyWindow:

'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.

Maybe:
a UIApplication extension:
extension UIApplication {
/// The app's key window taking into consideration apps that support multiple scenes.
var keyWindowInConnectedScenes: UIWindow? {
return windows.first(where: { $0.isKeyWindow })
}
}
Usage:
let myKeyWindow: UIWindow? = UIApplication.shared.keyWindowInConnectedScenes

But you're still using shared on the last line :)

Haven't tried, just found this as a answer to be honest ;-)

Aha ok 👌

here is a PR related to this for CodeScanner:
https://github.com/twostraws/CodeScanner/pull/37/files

The problem is that we don't have anything to use as a reference.

I tried this with Xcode beta 1 and everything seems to work fine. How do you run into this problem?

I think it is a breaking change in beta 3

Do you face this problem in the package, demo app or in an app of your own? If so, do you use CocoaPods or SPM?

Sorry for not adding this: in our own app with SPM:
url: "https://github.com/danielsaidi/Sheeeeeeeeet.git",
.exact("3.1.4")

Thank you! I am downloading Xcode 13 beta 3 now.

If you find a way to solve this without changing the api:s before I do, please let me know.

maybe marking the functions unavailable for iOSApplicationExtension will help?

@available(iOSApplicationExtension, unavailable)
func addActionSheet(_ sheet: ActionSheet, to vc: UIViewController)

@available(iOSApplicationExtension, unavailable)
open override func present(_ sheet: ActionSheet, in vc: UIViewController, view: UIView? = nil, item: UIBarButtonItem? = nil, completion: @escaping () -> ())

@available(iOSApplicationExtension, unavailable)
func addActionSheetToKeyWindow(_ sheet: ActionSheet)

That's a great idea, I will try it :)

@apps4everyone Hmmm, I don't get an error when I build Sheeeeeeeeet with Xcode 13 beta 4, but I do for other open source projects like SwiftUIKit. In these projects, your fix works 🎉

How do you run into the problem in Sheeeeeeeeet? In the package, demo app or in your own app? I will try investigating.

Maybe if the app has an extension? We have notifications extension.

The extension shouldn't add Sheeeeeeeeet as a dependency, though.

I solved this by removing UIApplication.shared instead of using the extension unavailable annotation, since that has many side-effects that I could not get around.

I have released this fix as a 3.2.