Before reading the question please see this video, so you will understand the issue/problem in the app.
What I am trying to do is that,
Case 1: If the user is not logged into the app then after opening the App Login view will open and after giving username and password then it will navigate to the Home page.
Case 2: If the user is already logged in then after starting the app it will home page.
I wrote code to archive this,
In the login page, code for Login button
- (IBAction)loginButton:(id)sender {
[self->userdefaults setBool:YES forKey:@"loginSuccess"];
[userdefaults synchronize];
HomeViewController *home=[self.storyboard instantiateViewControllerWithIdentifier:@"homeId"];
[self.navigationController pushViewController:home animated:YES];
}
I am storing one value in NSUserDefaults
, and after restarting or opening the app, in AppDelegate
class I am checking the condition that NSUserDefaults
having that value, if yes then it will show direct homepage if not then it will login page.
Check below code which is written in AppDelegate
class,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
userdefaults=[NSUserDefaults standardUserDefaults];
mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"loginSuccess"]) {
NSLog(@"Login Done!!!");
HomeViewController *homeVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"homeId"];
SampleNavigationController *navigation = [[SampleNavigationController alloc] initWithRootViewController:homeVC];
// SWRevealViewController * vc= [[SWRevealViewController alloc]init];
// ExpandableTableViewController *sidemenu = (ExpandableTableViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"sideMenu"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
}else
{
LoginViewController *loginVC=[mainStoryboard instantiateViewControllerWithIdentifier:@"LoginId"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = loginVC;
[self.window makeKeyAndVisible];
}
return YES;
}
In the home page, after clicking on the left navigation button side-menu view is not opening/showing.
What is the code missing in AppDelegate
class?