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

后端 未结 8 979
爱一瞬间的悲伤
爱一瞬间的悲伤 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:24

    Swift 5.1

    Works for me

    If you are also looking for a way to deal with foreground and background modes you should try this

    UIApplication.shared.windows.first(where: { $0.isKeyWindow })
    
    0 讨论(0)
  • Don't call window in didLoad function call the keyWindow in viewDidAppear function of ViewController

    0 讨论(0)
提交回复
热议问题