How do I get the keyWindow reference in a swift app?

后端 未结 8 988
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 03:55

In Objective-C in the viewDidLoad method of a UIViewController I do this to get the keyWindow reference in my iOS app:

 UIWindow * keyWindow = [[UIApplication sh         


        
8条回答
  •  花落未央
    2021-02-12 04:18

    Swift 4 simply has UIApplication.shared.keyWindow property, no casting necessary.

    Note that iOS 13/iPadOS introduces UIScenes and explicit support for multiple windows, and thus deprecates the concept of keyWindow as it is no longer valid.

    This question has an overview how to get access to scene based windows.

提交回复
热议问题