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