0
- (void)someMethodThatIsCalledTwice{

    NSURLSession *session = [NSURLSession sharedSession];
            NSString *noteDataString = [NSString stringWithFormat:@"album_id=%@&pic_id=%@", albumId,photoId];
            NSURL *url = [NSURL URLWithString:stringUrl];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
            NSLog(@"PARAMS: %@", noteDataString);
            request.HTTPBody = [noteDataString dataUsingEncoding:NSUTF8StringEncoding];
            request.HTTPMethod = @"POST";

            NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

            }];
}

This problem is that if I call this method twice passing different request.HTTPBody the dataTask gets the the noteDataString from the second call for both first and second call.

1 Answers1

0

Pass albumId and photoId as parameters to someMethodThatIsCalledTwice: like,

- (void) someMethodThatIsCalledTwiceForAlbumId:(NSString *)albumId photId:(NSString *)pahotId {

     //do the stuff
}
Akhilrajtr
  • 5,170
  • 3
  • 19
  • 30
  • It doesn't work @Akhilrajtr. Is still changing the parameters.. Seems like the NSSURLDataTask block from the first call is executed when the second call was already done and the block is getting parameters from the second call. – Albert Villanueva Carreras Jul 09 '15 at 11:05