Implementation of the IOS login feature

Source: Internet
Author: User

#import "AppDelegate.h"

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {

Override point for customization after application launch.

Determine whether to log in, from the login status to determine the start page//Get Userdefault

Nsuserdefaults *userdefault = [Nsuserdefaults standarduserdefaults]; NSString *name = [userdefault objectforkey:@ "name"];

Get Storyboard

Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Main" Bundle:[nsbundle Mainbundle]];

Change the root view controller to the login view controller if the user is not logged in

if (name = = Nil) {

NSLog (@ "%@", name);

ID view = [storyboard instantiateviewcontrollerwithidentifier:@ "LoginView"];

Self.window.rootViewController = view;

}

return YES;

}

#import "ViewController.h"

#import "LapLoginViewController.h"//Import

#import "NetWorkManger.h"//import (this is a third party I wrote, parsing the URL, can be found in my blog, no longer cumbersome here);

@interface Viewcontroller ()

@property (Weak, nonatomic) Iboutlet Uitextfield *nametextfiled;

@property (Weak, nonatomic) Iboutlet Uitextfield *passwordtextfiled;

@property (Nonatomic,strong) nsdictionary *datasource;

@end

@implementation Viewcontroller

-(Nsdictionary *) DataSource {

if (!_datasource) {

Self.datasource = [Nsdictionary dictionary];

}

return _datasource;

}

Storyboard dragged out of the button, landed

-(Ibaction) Loginaction: (ID) Sender {

Get information entered by the user

NSString *username = Self.nameTextFiled.text;

NSString *password = Self.passwordTextFiled.text;

NSString *str = [NSString stringwithformat:@ "Http://hy.gdhstz.com/Hander/Admin_Handler.ashx? action=login&userphone=%@&fpwd=%@ ", Username,password];

[[Networkmanger Mainnetworkmanager] getdatewithurl:str success:^ (Networkmanger *net, id object) {

NSLog (@ "%@", object);

} fail:^ (Networkmanger *net, Nserror *error) {

}];

Validation of user information

if (Username.length > 10) {

[[Networkmanger Mainnetworkmanager] getdatewithurl:str success:^ (Networkmanger *net, id object) {

if (object = = nil) {

Uialertview *alert;

alert = [[Uialertview alloc] initwithtitle:@ "Sorry" message:@ "account password is incorrect, please re-enter" Delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil, nil];

[Alert show];

}else {

Get Userdefault single case

Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];

Save username and password to Userdefault after successful login

[Userdefaults setobject:username forkey:@ "name"];

[Userdefaults setobject:password forkey:@ "password"]; [Userdefaults Synchronize];

To jump to the main interface with a modal

Laploginviewcontroller *LAPVC = [[Laploginviewcontroller alloc] init];

[Self.navigationcontroller PUSHVIEWCONTROLLER:LAPVC Animated:yes];

}

} fail:^ (Networkmanger *net, Nserror *error) {

Uialertview *alert;

alert = [[Uialertview alloc] initwithtitle:@ "Sorry"

message:@ "Account password is incorrect, please re-enter"

Delegate:self

cancelbuttontitle:@ "OK"

Otherbuttontitles:nil, nil];

[Alert show];

}];

}else{

Uialertview *alert;

alert = [[Uialertview alloc] initwithtitle:@ "Sorry"

message:@ "Account password is incorrect, please re-enter"

Delegate:self

cancelbuttontitle:@ "OK"

Otherbuttontitles:nil, nil];

[Alert show];

}

}

After landing to jump to the interface, the button method of the interface to log off the login;

#import "LapLoginViewController.h"

@interface Laploginviewcontroller ()

@end

@implementation Laploginviewcontroller

-(Ibaction) Hahahahahahahah: (ID) Sender {

Get Userdefaults single case

Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];

Removing user information stored in the Userdefaults

[Userdefaults removeobjectforkey:@ "name"];      [Userdefaults removeobjectforkey:@ "password"]; [Userdefaults Synchronize];

Get Storyboard

Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Main" Bundle:[nsbundle Mainbundle]];

Get the page to jump after logging off

ID view = [storyboard instantiateviewcontrollerwithidentifier:@ "LoginView"];

Modal Display landing page

[Self Presentviewcontroller:view Animated:yes completion:^{}];

}

Implementation of the IOS login feature

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.