简体   繁体   English

在iOS中避免/禁用状态保存

[英]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 启动屏幕->屏幕X->屏幕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. 我也检查了其他一些应用程序,但它们的行为方式不正确,例如Google Maps。

I also have implemented following two methods in AppDelegate as follows 我还在AppDelegate中实现了以下两种方法,如下所示

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 不知道这是否有帮助,但是您可以像我一样始终使用并使用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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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