Search code examples
swiftios12

Prevent appearing of last accessed view after launch screen when app is restarted in iOS?


I’ve created iOS app, where Im facing small issue related to UI.
Say app is having launcher, view1 and view2 screens.
Assume App is launched, after that view1 is loaded, from there view2 is loaded (ex. on button press).
Now user quit the app and re-started. Now after launcher screen, view2 appears for fraction of second before view1 appears.

I tried following code, but still Im not able to avoid appearing of view2 after launcher and before view1. I assume this is due to app restoration feature of iOS.

In AppDelegate, added below code -

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

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

Any help.. please..:)


Solution

  • You are missing an underscore in the function signature. Try

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

    But I don't think this method does what you need.

    See https://developer.apple.com/library/archive/qa/qa1838/_index.html for one of Apple's solutions