简体   繁体   中英

Avoid/Disable state preservation in iOS

I'm working on a small App having following sort of interfaces (for assumption)
Launching Screen -> Screen X -> Screen Y

The problem is that when I close the app and open it again simultaneously it again shows me the last seen screen and then later on shows Launching screen and then the initial view controller.

I've checked some other Apps as well but they aren't behaving this way eg google maps.

I also have implemented following two methods in AppDelegate as follows

func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
        return false
    }

func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
        return false
    }

But nothing is working. Can someone please suggest what should I do

Thanks.

Not sure if this would help but you could always do as I do and make use of NotificationCenter

// In something like viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(returnedFromBackground), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)

...

@objc func returnedFromBackground() {
    // Anything you want to preserve/save/do and then segue (or whatever you use) to your launching screen
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM