#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