Open-source Chinese iOS client learning-(12) User Login

Source: Internet
Author: User

In the previous blog's open-source Chinese iOS client study-(11) What is the process of saving the user name and password to the local sandbox and reading the user name and password from the local machine?

-(void)saveUserNameAndPwd:(NSString *)userName andPwd:(NSString *)pwd{    NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];    [settings removeObjectForKey:@"UserName"];    [settings removeObjectForKey:@"Password"];    [settings setObject:userName forKey:@"UserName"];    pwd = [AESCrypt encrypt:pwd password:@"pwd"];    [settings setObject:pwd forKey:@"Password"];    [settings synchronize];}


The above method uses the NSUserDefaults class, which also implements the data function in the form of a dictionary and saves the data to the local application sandbox. This method is suitable for storing small data, for example, the user logs in to the configuration information. This code first defines an object for initialization and removes the objects whose key values are UseName and Password to prevent interference caused by data confusion; then, you can reset the key value information; [settings synchronize]; synchronize the key value information to the local directory;

Now let's look at the user configuration information in the sandbox.

First, check the application sandbox path and use


    NSString *homeDirectory = NSHomeDirectory();    NSLog(@"path:%@", homeDirectory);

Print result: path:/Users/DolBy/Library/Application Support/iPhone Simulator/5.1/Applications/55C49712-AD95-49E0-B3B9-694DC7D26E94


But there is no Library directory under my DolBy user, because the system hides these file directories. Now you need to display these hidden files and open the terminal and enter defaults write com. apple. finder AppleShowAllFiles-bool true press enter, and then restart the Finder (no? See the iOS sandbox (SanBox) file. Find the net. oschina. iosapp. plist file under Library/Preferences in the 55C49712-AD95-49E0-B3B9-694DC7D26E94 directory and open it.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0A2041Q5-0.png "style =" float: none; "title =" QQ20130522-4.png "/>

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0A2041093-1.png "style =" float: none; "title =" QQ20130522-5.png "/>


It is not difficult to see some basic information of the user stored in the local sandbox, as well as some configuration information, as well as the time when the data was last acquired;


Log on to the loginView class under the Setting directory. Check loginView. xib first. The interface is relatively simple. It may be missing an artist;

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0A2044546-2.png "style =" float: none; "title =" QQ20130522-6.png "/>

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0A2044U7-3.png "style =" float: none; "title =" QQ20130522-8.png "/>


Declare part of the file from scratch

# Import <UIKit/UIKit. h> # import "Tool. h "# import" ProfileBase. h "# import" MessageView. h "# import" Config. h "# import" MBProgressHUD. h "# import" MyThread. h "@ interface LoginView: UIViewController <UIWebViewDelegate> {// ASI class library, obtain network requests, perform login verification ASIFormDataRequest * request;} // accept username input @ property (strong, nonatomic) IBOutlet UITextField * txt_Name; // the user's password @ property (strong, nonatomic) IBOutlet UITextField * txt_Pwd is accepted; // The switch button, set whether the user should remember the user name and password @ property (strong, nonatomic) IBOutlet UISwitch * switch_Remember; // mark the role, used to record whether a warning @ property BOOL isPopupByNotice is prompted when an exception or error is returned in the request data; // webView, layout a web page on the mobile phone and display the description information, if rich text is used on this web page, you can directly jump to the url @ property (strong, nonatomic) IBOutlet UIWebView * webView; // login processing-(IBAction) click_Login :( id) sender; // cancel the first response object of two textfiles-(IBAction) textEnd :( id) sender; // cancel the first response object of the keyboard, click the keyboard that is displayed on the page-(IBAction) backgrondTouch :( id) sender; // Save the user name and user ID to the local device based on the returned data-(void) analyseUserInfo :( NSString *) xml; @ end

Paste the main method code in the implementation file

-(Void) viewDidLoad {[super viewDidLoad]; [Tool clearWebViewBackground: webView]; [self. webView setDelegate: self]; self. navigationItem. title = @ "login"; // determines whether the user name and password NSString * name = [Config Instance] are displayed. getUserName; NSString * pwd = [Config Instance]. getPwd; // if the user name and password exist and are not empty, the corresponding text if (name &&! [Name isEqualToString: @ ""]) {self.txt _ Name. text = name;} if (pwd &&! [Pwd is1_tostring: @ ""]) {self.txt _ Pwd. text = pwd;} UIBarButtonItem * btnLogin = [[UIBarButtonItem alloc] initWithTitle: @ "login" style: UIBarButtonItemStyleBordered target: self action: @ selector (click_Login. navigationItem. rightBarButtonItem = btnLogin; self. view. backgroundColor = [Tool getBackgroundColor]; self. webView. backgroundColor = [Tool getBackgroundColor]; // NSString * html = @ "<body style = 'background-color: # ebebf3'> 1, you can go to <a href =' http://www.oschina.net '> http://www.oschina.net </A> register an account for login for free <p/> 2. If your account is registered using OpenID, we recommend that you set a password for your account on the Web page <p/> 3. You can click <a href =' http://www.oschina.net /Question/12_52232 '> here </a>

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.