IOS is actively logged in and the loading page is always displayed during login

Source: Internet
Author: User
Tags blank page

In iOS development, it is assumed that the client does a bit of humanization and will definitely consider actively logging in

In fact, the principle is very easy, that is, after the first successful login to the username and password deposit Userdefault the next time you log in to infer Usedefault there is no storage usernamepassword, If you have some words, bypass the login interface and log in directly

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


The general implementation of their own active login is in the loading page to implement.

However, login is generally required to communicate with the server. is asynchronous, and the load page is in the main thread. This will not control the load page to disappear after the login is complete (that is, after the server returns information)


The problem I encountered is that the login is not complete and the loading page is complete. You will jump out of a blank page. After you have actively logged in, will not jump home page

The solution is to do a Viewcontrol interface and loading page exactly the same, the normal download page is a picture for example, loading the page is




The Viewcontroller in our own meeting just need to set up a full screen picture, the loading page picture to put on.

And then appdelegate that the assumption is that you are actively logged in to directly

Rootviewcontroller

Set as our own new Viewcontroller

Then log in and do a jump.


On the Code


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

@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 username password (MD5 encrypted. This can be directly pulled over to the dictionary. Then save the dictionary to Userdefault



Down in the appdelegate to infer whether usedefault in real username password have the words to start their own active 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];            }


The inference hypothesis is that self-login is the first to speak Rootviewcontroller set up for our own Viewcontroller

And then call yourself the active login method

Once you have actively logged in, you can set Rootviewcontreler again.


-(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 loading a child view, so it is called once contactcontroller, otherwise there is only the first Controller tab icon on the first display. Contactcontroller tab icon does not display for    (Uiviewcontroller *controller in tabbarc.viewcontrollers) {        Uiviewcontroller *view= controller.view;    }    [UIApplication Sharedapplication].keywindow.rootviewcontroller=tabbarc;}

Ok suppose there's a problem welcome plus QQ Discussion




Apple Development Group: 414319235 Welcome to add welcome discussion questions





IOS is actively logged in and the loading page is always displayed during login

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.