present viewcontroller on top from app delegate

1.6k views Asked by At

so i've spent the last 5-6 hours trying to get this one feature to work and i've run into a couple of pitfalls in my implementation and limits of understanding. I've tried a couple of methods:

Method 1 :

func applicationWillEnterForeground(_ application: UIApplication) {

    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    var vc : UIViewController

    vc = storyboard.instantiateViewController(withIdentifier: "PasscodeLockVC")

    self.window?.rootViewController = vc
    self.window?.makeKeyAndVisible()
    print("app entered foreground")

}

Issue : I can't dismiss the screen from the PasscodeLockVC (it's the passcode VC).

Method 2 :

public extension UIViewController {
func show() {
    let win = UIWindow(frame: UIScreen.main.bounds)
    let vc = UIViewController()
    vc.view.backgroundColor = .clear
    win.rootViewController = vc
    win.windowLevel = UIWindowLevelAlert + 1
    win.makeKeyAndVisible()
    vc.present(self, animated: true, completion: nil)
}

func hide() {
    dismiss(animated: true, completion: nil)
}

}

Issue : I get a black screen when i dismiss.

**So my questions is ** Can someone direct me on the best method to have my lock screen present upon entering foreground (i know it goes in applicationWillEnterForegroud), but when i do so, it preserves the screen that was active when the app was closed (will all of it's contents since it's a diary app)? I've been stumped all day and could really use some direction.

Running on most recent Xcode

0

There are 0 answers