0

I have an iOS app which provides some services to non-registered users and more services to registered users.

Every time I open the app, it opens on the default visitor page and I have to log in again.

I want the app to check if the user is logged in or not, then redirect him to the correct page.

I'm using storyboard, and I think this has something to do with didFinishLaunchingWithOptions:.

Trott
  • 66,479
  • 23
  • 173
  • 212
Nahar
  • 101
  • 6
  • I'm guessing you didn't try anything since the answer to the problem is very wide. – Desdenova Apr 16 '13 at 08:49
  • your problem solved or not?? you are stucking about saving the data or redirecting the page?? – Gopesh Gupta Apr 16 '13 at 09:14
  • Yeah it solved now, I was stuck with both. I found how to redirect in this url http://stackoverflow.com/questions/9828217/programmatically-call-storyboard-in-delegate and I understood how to save data in this page – Nahar Apr 16 '13 at 10:47

2 Answers2

1

I really don't think what @Necro is doing is necessary.

Why not just check for an active session each time the app is brought into the foreground, and if there isn't one, present (modally) your login view controller without animation. This kind of architecture makes for very clean logic when logging out as well because all you do is clear the session, present the login view controller, and pop your main navigation hierarchy to it's root view controller.

Simple.

jakenberg
  • 2,125
  • 20
  • 38
0

You can use NSUserDefaults to save information about your application.

When the user successfully logs into your app, you can Store the status of a user perviously logging in correctly.

    //SETTING USER DEFAULTS
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:txtUsername.text forKey:@"Username"];
    [defaults setObject:txtPassword.text forKey:@"Password"];
    [defaults setObject:"true" forKey:@"LoginStatus"];
    [defaults synchronize];

    //RETRIEVING USER DEFAULTS 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *Username = [defaults objectForKey:@"Username"];
    NSString *Password = [defaults objectForKey:@"Password"];
    NSString *Status = [defaults objectForKey:@"LoginStatus"];

Then once you have this working you can then apply some logic to it.

    if ([Status isEqualToString:@"true"]) {
        [self loginUser:Username :Password]
    }

------ EDIT ------

Someone in comments said it may be trouble to store a password here. Go to this: Queston to get a function to hash the password string.

Lastly thankyou to all those who voted me back into the positive.

Community
  • 1
  • 1
Necro
  • 333
  • 5
  • 18
  • 1
    Whoever down voted, Why? this question is already obscure and open-ended as it is. I just decided to try and help. Maybe i should think twice next time. – Necro Apr 16 '13 at 09:01
  • If you like this answer please press the green tick. – Necro Apr 16 '13 at 09:07
  • 4
    I didn't down vote you, but I can guess one of the reasons are you suggest storing secure data (password) in a non secure area. – LJ Wilson Apr 16 '13 at 09:29
  • 1
    Then he can hash the password. – Necro Apr 16 '13 at 09:32