Code extraction of Network Load data and Single tool class

Source: Internet
Author: User

Today to share one by one Network load data: First look at the code bar--------------------------


-(void) Diseasenumwithfinishedblock: (finishedblocks) finishedblock{ nsstring *urlstr = @ "/HTTP Data Interface"; Nsdictionary *prama = @{response parameter}; [[Networktool Sharednetworktool] post:urlstr parameters:prama progress:^ (nsprogress * _Nonnull uploadProgress) { NSLog (@ "Progress"); } success:^ (Nsurlsessiondatatask * _nonnull task, id _nullable responseobject) { nsdictionary *result = [ Nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingallowfragments Error:NULL]; NSLog (@ "%@----", result); Take out the data inside the array nsdictionary *ARRM = result[@ "Data"]; Finishedblock (ARRM); NSLog (@ "Success"); } failure:^ (Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) { NSLog (@ "failed"); }]; }

Here the main use of the block value, first define a block, such as:

typedef void (^finishedblocks) (nsdictionary * diseanumwihtfinished);

A single example is also used:

The. h file
#import <AFNetworking/AFNetworking.h> @interface networktool:afhttpsessionmanager+ (instancetype) Sharednetworktool; @end

In the. m file
Static Networktool *_instance;+ (instancetype) sharednetworktool{ static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{ _instance = [[Networktool alloc] initwithbaseurl:nil]; _instance.responseserializer.acceptablecontenttypes = [Nsset setwithobjects:@ "Application/json", @ "Text/json", @ " Text/javascript ", @" text/html ", @" Text/plain ", nil]; By default, the response is resolved by using JSON to parse //To change the default JSON deserialization to our most common binary _instance.responseserializer = Regardless of what the server returns to us. Afhttpresponseserializer Serializer]; The serialization of the request is by default a pure binary, which is changed to the serialized way of the JSON binary _instance.requestserializer = [Afjsonrequestserializer serializer]; }); return _instance;}

Then to assign a value to a property, define a global property to receive it, and get the result you want! When you do not get the value of the network load must be quiet to think about their own ideas, any one may have to try, because only in constant verification you can know what you need to realize the function. Let's get here today. Welcome to have a problem exchange Oh hey-------??????

Code extraction of Network Load data and Single tool class

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.