I know that I should use this when I get an interruption in the app and it comes back:
- (void)applicationDidBecomeActive:(UIApplication *)application
But how would I, when the app becomes active again, dismiss any previously opened view controllers and present the main view controller?
This may depend on your architecture. If you use an UINavigationController to manage your views, you could call
popToRootViewControlleron it to push everything else off the navigation stack and return to the root view (you’d have to maintain a property or something similar in your application delegate). If you have any modal views open, you could maintain a property in your application delegate that contains the currently active modal dialogue (if any) which would be dismissed.Note though that
applicationDidBecomeActive:is also called when the application was put into the background (e.g. because the user went for another app in the meantime) and the user returns to your app (as well as on first launch), so returning to the root view may be something different than the user expects.