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

后端 未结 8 975
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 04:07

    The key window must not yet be set at the time of viewDidLoad. Your code works fine in viewDidAppear. Alternately, you can get the windows array in viewDidLoad, and get one (if there's more than one) of the windows from that array.

提交回复
热议问题