I have been banging my head against the wall with this issue, but since I updated to iOS 10.1, any view added to UIApplication.shared.keyWindow
does not seem to render. It is simply invisible.
I happen to have a test phone with iOS 9.3.2 running in it and the added views DO appear visible.
NB: I have been using this for a long time to show "in app notifications" and it has been working like a charm.
It is a VERY simple piece of code and does not throw any errors whatsoever.
let view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = UIColor.red
let window = UIApplication.shared.keyWindow
window?.addSubview(view)
I have checked the following:
the window is not nil and has a perfectly valid frame. Same goes for the UIView I add, and it does appear in the view hierarchy. I have also tried moving the code around, putting it in ViewDidAppear, ViewDidLayoutSubViews etc… but to no avail.
Any ideas? Anybody else facing the same issue?
EDIT: Seeing some of the comments below, I believe I need to clarify: this piece of code should work (if I take reference on Apple documentation). Also, the issue is iOS 10 specific. In versions < iOS 10 it works perfectly.
So I am not looking for where this called should be called but rather for what may have changed in iOS 10 that would bring this behaviour.
Thanks