Kritias
Kritias

Reputation: 187

In which method should I check for NSUserDefaults?

In my iOS app I made a Login page as the entry point of the app (using storyboard) However I don't want the user to see the login page each time he uses the app, so I thought of launching the Home page of the app if the user already performed a login in the past.

For that I started to save the login act with NSUserDefaults but I do not know in which of the LoginViewController method I should check for it? Also, is this way to feature "auto logging" a good practice?

Upvotes: 0

Views: 25

Answers (1)

Avijit Nagare
Avijit Nagare

Reputation: 8802

Best place is in application:didFinishLaunchingWithOptions

  if ([[NSUserDefaults standardUserDefaults] integerForKey:@"UserID"]==0) {
    //no user login go back to login page
}
else{
       //go in main screen of you application as user already login "root" is storyboard ID of main screen
        self.window.rootViewController=[self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"root"];

}

Upvotes: 1

Related Questions