dwinnbrown
dwinnbrown

Reputation: 4009

How to restart an app when resumes from multi-tasking

So my app relies on an internet connection and every time the app is opened from the home screen it checks using Reachability and then allows the user to continue or tells them to get connected. My issue however is that when the app is resumed from multitasking, it skips the initial view controller and goes straight to where they were. Is there any way in swift that I could get the app to refresh or restart when it is resumed from multi-tasking?

Thanks

EDIT When using this code:

let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)
self.window.rootViewController = MainStoryboard.instantiateInitialViewController()

I get expected declaration error. enter image description here

Upvotes: 1

Views: 7809

Answers (3)

S.M_Emamian
S.M_Emamian

Reputation: 17383

You can use navigation controller:

    let vc = self.storyboard!.instantiateViewController(withIdentifier: "FirstPageViewController") as! FirstPageViewController
    self.navigationController?.pushViewController(vc, animated: true)

Upvotes: 0

dwinnbrown
dwinnbrown

Reputation: 4009

I just added the following in the plist: "Application does not run in background" and set it to "YES"

Seem to be working.

Upvotes: 2

Asaf
Asaf

Reputation: 2168

You can set your root view controller and it will restart you main VC. Assuming your using a storyboard:

(self is referring to your AppDelegate)

Swift:

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
self.window.rootViewController = storyboard.instantiateInitialViewController()

Objective-C:

self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MyStoryboardName" bundle:nil] instantiateInitialViewController];

Upvotes: 7

Related Questions