Easy use of iOS network processing--afnetworking

Source: Internet
Author: User

iOS processing network requests, with more than the third-party tool class afnetworking, because the native is more troublesome.

If you log in to send account and password with the background comparison, the process is as follows, back in the background is JSON, such as

{"Login": {"id": "0001", "status": "OK", "errormsg": ""}}

Here is an example of when to use.

1 #import "AFNetWorking.h"2 3NSString Urllogin =@"www.xxx.com";4 //Create request Manager5Afhttprequestoperationmanager *requestmanager =[[Afhttprequestoperationmanager alloc] init];6 //affirm that the requested data is of type text/html7RequestManager.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@"text/html", nil];8RequestManager.requestSerializer.HTTPShouldHandleCookies =YES;9 [Requestmanager get:urlloginTen Parameters:nil Onesuccess:^ (Afhttprequestoperation *operation,IDresponseobject) { ANsdictionary *dict = responseobject[@"Login"]; -NSString *str = [Dict objectforkey:@"Status"]; -NSString *errormsg = [Dict objectforkey:@"errormsg"]; the                 //If you succeed, jump to the next page -                 if(str && [str isequaltostring:@"OK"]) { -Mstabbarviewcontroller *tabbar =[[Mstabbarviewcontroller alloc] init]; - [self Presentviewcontroller:tabbar animated:yes completion:nil]; +}Else { -                 //The comparison is not successful, pop-up hints +Self.alertview = [[Uialertview alloc]initwithtitle:@""Message:errormsgDelegate: Self Cancelbuttontitle:@"cancle"Otherbuttontitles:@"OK", nil]; A [Self.alertview show]; at                 } -                  -} failure:^ (Afhttprequestoperation *operation, Nserror *error) { -NSLog (@"Server Error"); -}];

Of course, the premise is to introduce afnetworking files.

Easy use of iOS network processing--afnetworking

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.