IOS Automatic login, the loading page is always displayed during login

Source: Internet
Author: User
Tags blank page

iOS Development If the client does a bit of humanization will certainly consider automatic login

In fact, the principle is very simple, that is, after the first successful login to the user name and password Userdefault the next login to determine whether the user name password Usedefault, if you have to bypass the login interface directly login

But in the process of doing encountered a problem now do a tidy, for everyone to learn, correct me


The general implementation of automatic login is in the loading page to implement,

However, the login generally needs to communicate with the server, is asynchronous, and load the page in the main thread, so that the load page can not control the completion of the login (that is, after the server returned information) and then disappear


The problem I encountered was that the login was not completed and the loading page was completed. Will jump out of a blank page, and so on when the automatic login is completed before jumping to the homepage

The solution is to do a Viewcontrol interface and load the page exactly the same, generally loading the page is a picture such as loading the page is




The Viewcontroller in our own view only needs to set up a full screen picture, the loading page picture to put up.

And then appdelegate to determine if the automatic login will be directly

Rootviewcontroller

Set as our own new Viewcontroller

And then do a jump when you're done logging in.


On the Code


The first is my own new viewcontroller only need to load a picture can

@implementation viewcontroller-(void) viewdidload {    [super viewdidload];    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 the can be recreated.} @end



After the first login is successful, the user information is saved

     Nsuserdefaults *userd=[nsuserdefaults Standarduserdefaults];        [UserD setvalue:loginuserinfo forkey:@ "Loginuserinfo"];

My practice is to put the user name password (MD5 encrypted so that you can pull it directly) into the dictionary, and then save the dictionary Userdefault



Down in the appdelegate to determine whether there is a user name password in the Usedefault to start automatic login


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];            }


Judging if it is automatic login first speak Rootviewcontroller set for our own created Viewcontroller

And then call the automatic login method

Reset Rootviewcontreler After automatic login is complete


-(void) loginsuccess{        homeviewcontroller *homevc=[[homeviewcontroller alloc]init];    Exploreviewcontroller *explorevc=[[exploreviewcontroller Alloc]init];    Enjoyviewcontroller *enjoyvc=[[enjoyviewcontroller Alloc]init];    Userinfoviewcontroller *userinfovc=[[userinfoviewcontroller Alloc]init];        Uitabbarcontroller *tabbarc=[[uitabbarcontroller Alloc]init];    [Email protected] [HOMEVC,ENJOYVC,EXPLOREVC,USERINFOVC];    Note By default, Uitabbarcontroller is lazy-loaded when the child view is loaded, so it is called once contactcontroller, otherwise only the first Controller tab icon is displayed for the first time, Contactcontroller tab icon does not display for    (Uiviewcontroller *controller in tabbarc.viewcontrollers) {        Uiviewcontroller *view= controller.view;    }    [UIApplication Sharedapplication].keywindow.rootviewcontroller=tabbarc;}

Ok if there is a problem welcome to QQ Discussion




Apple Development Group: 414319235 Welcome to join the Welcome discussion question





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS Automatic login, the loading page is always displayed during login

Related Article

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.