I am working on an app that at launch checks for valid login credentials, and if they are found and not expired the main split view controller is displayed, and if not a login screen should be displayed.
Each part is working fine separately, but I am struggling with the best way at launch time to select the proper view to display.
I have tried setting up a modal segue from the root view controller, and in my application:didFinishLaunchingWithOptions: function in the App Delegate, calling this:
// Segue to the login view controller...
if (loginNeeded) {
[self.window.rootViewController performSegueWithIdentifier:@"LoginScreen" sender:self];
}
This logically should work, but triggering segues from within the app delegate seems to be impossible.
What is the ideal place and technique for handling this?
You could try a custom segue, as per this post hiding-a-segue-on-login-process.
Alternatively if you’re desperate to have the login display before the split view controller loads try something along the following lines…
Create your login screen on the main storyboard as, say, a subclass of
UIViewController. Make sure it is the initial scene (check Is Initial View Controller).On the storyboard, create a new segue from your login class to the original SplitViewController. Give it an identifier, ‘
Load SplitViewController‘ and a segue custom class name which we’ll callFullyReplaceSegue.In your login class .m file, add code to be called once the user has logged in:
Create the new segue class, based on
UIStoryboardSegueand name itFullyReplaceSegueas per above..h file
.m file