-4

I want the when user install apps on device app should show him loginScreen when user first time opens app after that user logins and user remains logins is there any way to make this save so that if user again opens app second then user should be in logged stated and does not show user the login screen thanks.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch.
    self.splitViewController =[[UISplitViewController alloc]init];
    self.rootViewController=[[RootViewController alloc]init];
    self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
    self.loginViewController=[[[LoginViewController alloc]init] autorelease];

    UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
    UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];

    if ([detailNav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) 
    {
        UIImage *image = [UIImage imageNamed:@"Nav.png"];
        [detailNav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    }

    user_Name=@"Jamshaid";
    isClickedLogin=@"NO";
    userLogin=@"Logout";

    self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
    self.splitViewController.delegate=self.detailViewController;

    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    self.coffeeArray = tempArray;
    [tempArray release];

    NSMutableArray *tempArray1 = [[NSMutableArray alloc] init];
    self.arrayOne = tempArray1;
    [tempArray1 release];

    NSMutableArray *tempArray2 = [[NSMutableArray alloc] init];
    self.arrayTwo = tempArray2;
    [tempArray2 release];

    NSMutableArray *tempArray3 = [[NSMutableArray alloc] init];
    self.libraryArray = tempArray3;
    [tempArray3 release];

    NSMutableArray *tempArray4 = [[NSMutableArray alloc] init];
    self.activityArray = tempArray4;
    [tempArray4 release];

    NSMutableArray *tempArray5 = [[NSMutableArray alloc] init];
    self.arrayOneC = tempArray5;
    [tempArray5 release];

    NSMutableArray *tempArray6 = [[NSMutableArray alloc] init];
    self.arrayTwoC = tempArray6;
    [tempArray6 release];

    NSMutableArray *tempArrayD = [[NSMutableArray alloc] init];
    self.detailArray = tempArrayD;
    [tempArrayD release];

    NSMutableArray *tempArrayD1 = [[NSMutableArray alloc] init];
    self.detailArrayOne = tempArrayD1;
    [tempArrayD1 release];

    NSMutableArray *tempArrayD2 = [[NSMutableArray alloc] init];
    self.detailArrayTwo = tempArrayD2;
    [tempArrayD2 release];

    NSMutableArray *tempArrayD3 = [[NSMutableArray alloc] init];
    self.publishArray = tempArrayD3;
    [tempArrayD3 release];

    [Coffee getInitialDataToDisplay:[self getDBPath]];

    // Add the split view controller's view to the window and display.
    // original working [window addSubview:self.splitViewController.view];
    [window addSubview:splitViewController.view];
    [window makeKeyAndVisible];

    return YES;
}
djf
  • 6,592
  • 6
  • 44
  • 62
Jaw Ali
  • 205
  • 5
  • 13
  • but how to track record that it should not get the user Name again and again – Jaw Ali Jul 03 '13 at 07:47
  • If app launches first time that means user has not logged in, show him login screen. After logged in save username in `NSUserDefault` and next time when user enters in app so check it in second launching of app. – TheTiger Jul 03 '13 at 07:50
  • @TheTiger i have given my code if app runs first time i will check in login screen then i may show login screen but where to other code as mince – Jaw Ali Jul 03 '13 at 07:52
  • What are you doing dude ... First write your code in proper manner. I cant read it. – TheTiger Jul 03 '13 at 07:54
  • My code is simple splitViewController code added in View I want you to please tell me if i am first time logged then may i also write this code in same else brackets or not – Jaw Ali Jul 03 '13 at 07:57
  • @TheTiger : It looks like OP has messed up everything for so much easy solution. – Bhavin Jul 03 '13 at 08:04
  • @Vin Can you please help me out – Jaw Ali Jul 03 '13 at 08:05

2 Answers2

0

I don't do iPhone development, but wouldn't this easily be achieved using a config file? For example:

  1. App start
  2. read config.xml
  3. is element firstlogin false or true?
    1. if true: show the loginscreen, once the user logs in, set element to true and save the xml.
    2. if false: don't edit the xml at all and just skip the loginscreen.
  4. run app

This would, of course, reset if the app is reinstalled, I figure.

0

Sample Code :

In yourViewController.h :

NSString *uname;
NSString *pwd;

In yourViewController.m :

- (IBAction) loginButtonClicked :(id)sender
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        // app already launched
        uname = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserName"];
        pwd = [[NSUserDefaults standardUserDefaults] valueForKey:@"PassWord"];
        //Use uname and pwd in your URL.
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        // This is the first launch ever
        [[NSUserDefaults standardUserDefaults] setValue:txtUserName.text forKey:@"UserName"];
        [[NSUserDefaults standardUserDefaults] setValue:txtPassWord.text forKey:@"PassWord"];
    }
}
Bhavin
  • 27,155
  • 11
  • 55
  • 94