Login verification for ios

Source: Internet
Author: User

Login verification for ios

We can use the third framework AFNetworking to communicate with the server using its post method. If the userId returned by the server is 10, the operation succeeds. If the returned userId is 11, the user name or password is incorrect.

-(Void) login :( id) sender {AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager]; NSString * url = @ "http: // container: 8080/upload_file_service/LoginServlet"; manager. responseSerializer. acceptableContentTypes = [NSSet setWithObjects: @ "text/html", nil]; NSDictionary * namepwd =@{@ "user": @ "admin", @ "pass ": @ "123"}; [manager POST: url parameters: namepwd success: ^ (AFHTTPRequestOperation * operation, id responseObject) {NSLog (@ "post -- >%@", responseObject ); NSDictionary * datare = [[NSDictionary alloc] init]; datare = responseObject; re = [datare objectForKey: @ "userId"]; appStatus * transvalue = [appStatus ready instance]; mainViewController * mainView = [self. storyboard instantiateViewControllerWithIdentifier: @ "second"]; mainView. delegate = self; transvalue. contextStr =__ name. text; NSNumber * fre = [[NSNumber alloc] initWithInt: 10]; BOOL flag = [fre isEqualToNumber: re]; if (flag) {[self presentViewController: mainView animated: YES completion: nil] ;}} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {NSLog (@ "% @", @ "incorrect user name or password") ;}] ;}


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.