i new afnetworking
. how can execute success , failure blocks of following
nsmutabledictionary *rus = [[nsmutabledictionary alloc] init]; [rus setvalue:@"1211" forkey:@"id"]; [rus setvalue:@"33" forkey:@"man"]; [[afhttprequestserializer serializer] requestwithmethod:@"post" urlstring:@"http://mysite.co/service.php" rus];
how show success or failure after executing above code fragment.
requestwithmethod not complete call, returns nsmutableurlrequest. need take request , make afhttprequestoperation. can set success/failure block on object , run start method.
nsmutabledictionary *rus = [[nsmutabledictionary alloc] init]; [rus setvalue:@"1211" forkey:@"id"]; [rus setvalue:@"33" forkey:@"man"]; nsmutableurlrequest *request = [[afhttprequestserializer serializer] requestwithmethod:@"post" urlstring:@"http://mysite.co/service.php" parameters:rus]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { // code success } failure:^(afhttprequestoperation *operation, nserror *error) { //code failure }]; [operation start];
all being said, using outdated version of afnetworking? method you're referencing deprecated.
- (nsmutableurlrequest *)requestwithmethod:(nsstring *)method urlstring:(nsstring *)urlstring parameters:(id)parameters error:(nserror *__autoreleasing *)error
above correct method use. should pass in error object.
finally, easier way accomplish you're doing afnetworking 2.0 below:
afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; [manager post:@"http://mysite.co/service.php" parameters:rus success:^(afhttprequestoperation *operation, id responseobject) { // code success } failure:^(afhttprequestoperation *operation, nserror *error) { // code failure }];
Comments
Post a Comment