3

In iOS12 and below I used to use something similar to this to show a window on top of everything to cover my app contents. This use to work but in iOS13 betas this does not work anymore.

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var coverWindow: UIWindow?

    func applicationDidEnterBackground(_ application: UIApplication) {
        if self.coverWindow != nil {
            // Skip since cover window is already showing
            return
        }
        let vc = UIViewController()
        let label = UILabel(frame: window!.bounds)
        label.text = "CoverWindow. Tap to app see contents"
        vc.view = label
        vc.view.backgroundColor = UIColor.lightGray
        let coverWindow = UIWindow(frame: window!.bounds)
        coverWindow.rootViewController = vc
        coverWindow.windowLevel = .alert
        coverWindow.makeKeyAndVisible()
        self.coverWindow = coverWindow
    }

}

Apparently window changes are not reflected in screen until app enters foreground again.

Question

Does anyone know how fix or workaround this? or maybe this approach is incorrect?

Any help would be highly appreciated

Notes

  1. I don't use a simple view because my app might be showing other windows too and my requirement is to cover everything.

  2. I don't use applicationWillResignActive because we want to only show coverWindow when it enters background. (TouchID authentication and other stuff might trigger applicationWillResignActive and coverWindow would incorrectly show)

Example code

Download Full working example code in Github (Run in iOS simulator 12 and 13 to see the difference)

nacho4d
  • 43,720
  • 45
  • 157
  • 240
  • I'd advise to use `applicationWillResignActive`, it's much more reliable on doing this, you can show touchID when user goes back to active state – Tj3n Sep 04 '19 at 02:31
  • TouchID authentication alerts actually make application resign active state. No only TouchID but push notification acceptance alerts too and many other services. I would need to use a BOOL flag en each case ... I would like to avoid this approach if possible – nacho4d Sep 04 '19 at 12:24
  • Hi, did you find solution? – birdy Jan 20 '20 at 15:42

2 Answers2

0

You have to implement application life cycle, you just delete it , add those app life cycle functions and implement your codes , it ll be run without error

ArunPrasath
  • 150
  • 5
  • Am I missing something? App application life cycle methods are optional. I removed because I thought they were not needed in this example. This runs fine in iOS12 and below (from iOS9 to iOS12). I wonder what method is missing – nacho4d Sep 04 '19 at 07:15
0

Answer to myself.

I reported this to Apple and it was fixed in iOS 13.1 or so. Latest version of iOS13 does NOT have this bug :)

nacho4d
  • 43,720
  • 45
  • 157
  • 240