I have a question that the best way to send AFNetworking results to the controller or the correct way is. Is it through a representative or notification?
I have created a class to create API calls which have code below so if this class is imported into another controller and the API calls this method to call. Do I need a representative or notification?
I have read and it is using delegates. I was also seen the codehal tutorial, in which he used the information of the controller from the model. .
I better hope to show my question added to the code below
AFHTTPSessionManager * Manager = [[AFHTTPSessionManager alloc] initWithBaseURL: baseurl]; // notification in the way to block [Manager: Path parameter: success parameters: ^ (NSURLSessionDataTask * operation, ID responseObject) {[[NSNotificationCenter defaultCenter] postNotificationName: notificationName object: userInfo zero: responseObject]; } Failure: ^ (NSURLSessionDataTask * operation, NSError * error) {[NSNotificationCenter defaultCenter] postNotificationName: notificationName object: zero]; }]; // representatives receive path blocks [manager inside path parameters: success parameters: ^ (NSURLSessionDataTask * operation, ID responseObject) {if ([representatives respondsToSelector: @selector (getUserFeedsDidFinish: resultDict :)]) {[representatives performSelector: @selector ( GetUserFeedsDidFinish: counting result :) withObject: auto withObject: resultDict]; }} Failure: ^ (NSURLSessionDataTask * operations, NSError * error) {if (rep answers representatives: selector (getUserFeeds: didFailWithResultDict :)) {[delegate tasks performing: @selector (getUserFeeds: didFailWithResultDict :) withObject: self withObject : [Object with NSDictionary dictionary: error.userInfo forKey: KEY_ERRORS]]; }}];
I would advise to use blocks, how?
+ (zero) requestLocation: (NSString *) googleReference completionBlock: I write a service for you, this one is written called Class Connection (void (^) (NSString * coordinates, NSError * Error) Handler {NSString * urlString = @ "https://maps.googleapis.com/maps/"; NSMutableDictionary * parametersDictionary = [NSMutableDictionary dictionary]; [ParametersDictionary Set Object: googleReference forKey: @ "Reference"]; [ParametersDictionary setObject: @ "true" for that: @ "sensor"]; [ParametersDictionary setObject: @ "key (not this)" for: @ "key"]; AFHTTPClient * HTTPClient = [FTP Client Client and BeSure: [NSDR URLWithString: urlString]]; NSURLRequest * URLRequest = [HTTPClient Request: Method method: @ "Receive" path: @ "API / location / description / Jason" parameter: parametersDictionary]; AFHTTPRequestOperation * Request Operation = [[FTPTRAQAction Operation Elok] InitvatRuest: URRACEC]; [Request Operation Set Ends BlockWithSuccess: ^ (FHttpQuest Operation * Operation, ID ResponseAbject) {NSER * Error = Zero; NSDictionary * response = [NSJSONSerialization JSONObjectWithData: responseObject option: NSJSONReadingMutableContainers Error: & amp; Error]; NSDictionary * dicGeo = [((NSDictionary *) [reaction objectForKey: @ "result"]) objectForKey: @ "geometry"]; NSDictionary * coords = [dicGeo objectForKey: @ "location"]; NSNumber * lat = [Coord ObjectFor: @ "Late"]; NSNumber * lng = [Coord ObjectFor: @ "LNG"]; NSString * coordinate = [NSString stringWithFormat: @ "% @,% @", letter description, lng.description]; Handler (coordinates, errors); } Failure: ^ (FHttpAEASTA Operation * Operation, NSERR * Error) {NSLog (@ "% @", Error); }]; [Request Started Operation]; }
Then to call this service:
[connection request location: @ "google reference (not this is)" is complete : ^ (NSString * coordinate, NSError * error) {// your code with results}
No comments:
Post a Comment