IOS Automatic Logon. The loading page is always displayed during logon. ios Automatic Logon

Source: Internet
Author: User
Tags blank page

IOS Automatic Logon. The loading page is always displayed during logon. ios Automatic Logon

In iOS development, if the client is user-friendly, automatic logon is certainly considered.

In fact, the principle is very simple, that is, after the first login is successful, the user name and password will be stored in userdefault the next login to determine whether usedefault has stored the user name and password, if so, directly log on without the login interface

However, I encountered a problem during the process. Now I want to help you learn and correct it.


Generally, automatic logon is implemented in loading pages,

However, login usually requires communication with the server, which is asynchronous. Loading pages is in the main thread, so that the loading page cannot be controlled and disappears after the login is complete (that is, after the server returns information ).


The problem I encountered was that the login was not completed and the page loading was completed. A blank page is displayed, and the homepage is displayed only after automatic logon is complete.

The solution is to make a viewControl interface and load the page exactly. In general, loading a page is an image. For example, loading a page is




In our own view, viewcontroller only needs to set a full screen image to load the page image.

Then, in appdelegate, you can determine that if you log on automatically

RootViewController

Set viewcontroller as our new viewcontroller

Then, after logging on, do the jump.


Code on


First, the viewcontroller I created only needs to load an image.

@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        UIImageView *imageView=[[UIImageView alloc]initWithFrame:SCREEN_FRAME];    imageView.image=[UIImage imageNamed:@"HelpSecond"];    [self.view addSubview:imageView];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end



After the first successful login, the user information will be saved

     NSUserDefaults *userD=[NSUserDefaults standardUserDefaults];        [userD setValue:loginUserinfo forKey:@"loginuserinfo"];

My practice is to save the username and password (md5 encrypted, which can be pulled directly) into the dictionary, and then store the dictionary into userdefault



Then, in appdelegate, determine whether usedefault has a user name and password.


 NSUserDefaults *userD=[NSUserDefaults standardUserDefaults];

 NSDictionary *loginUserinfoDic=[userD valueForKey:@"loginuserinfo"];                    if (loginUserinfoDic!=NULL) {                                [userD setValue:@"autologin" forKey:@"isautologin"];                ViewController *vc=[[ViewController alloc]init];                _window.rootViewController=vc;                                LoginViewController *loginVC=[[LoginViewController alloc]init];                [loginVC login:loginUserinfoDic];            }


Determine if automatic logon is enabled. First, set rootviewcontroller to our own viewcontroller.

Then call the automatic logon method.

After automatic logon, set rootviewcontreler again.


-(Void) loginSuccess {HomeViewController * homeVC = [[HomeViewController alloc] init]; javaseviewcontroller * javasevc = [[javaseviewcontroller alloc] init]; enjoyViewController * enjoyVC = [[EnjoyViewController alloc] init]; UserInfoViewController * userInfoVC = [[UserInfoViewController alloc] init]; optional * tabBarC = [[UITabBarController alloc] init]; tabBarC. viewControllers = @ [homeVC, enjoyVC, EVC, userInfoVC]; // note that by default, UITabBarController is lazy when loading sub-views. Therefore, contactController is called once here, otherwise, only the first controller tab icon is displayed for the first time. The tab icon of contactController is not displayed for (UIViewController * controller in tabBarC. viewControllers) {UIViewController * view = controller. view;} [UIApplication sharedApplication]. keyWindow. rootViewController = tabBarC ;}

OK. If you have any questions, please add qq for discussion.




Apple Development Group: 414319235 welcome to join discussions





Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.