AFNetworking iOS
Posted
by
Jeromiin
on Stack Overflow
See other posts from Stack Overflow
or by Jeromiin
Published on 2014-06-04T15:18:10Z
Indexed on
2014/06/04
15:24 UTC
Read the original article
Hit count: 224
I have a problem with a request in my app, I want to receive a json but because of the completion block my "PRINT 2" is print before my "PRINT 1" and of course my "PRINT 2" is null. I want the contrary and my "PRINT 2" to be filled but I can't manage to do it.
-(void) makeConnection {
NSURL *url = [NSURL URLWithString:[@"http://monsite.com/iPhonej/verifPseudo.php?login="stringByAppendingString:[_loginField.text stringByAppendingString:[@"&password=" stringByAppendingString:_passField.text]]]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.response = (NSDictionary *)responseObject;
NSLog(@"PRINT 1 : %@", self.response[@"la"][@"reponse"][0][@"rep"]);
[_dataLock lock];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Request Failed: %@, %@", error, error.userInfo);
}];
[operation start];
}
- (IBAction)logIn:(id)sender {
[self makeConnection];
NSLog(@"PRINT 2 : %@", self.response[@"la"][@"reponse"][0][@"rep"]);
}
I know that AFNetworking is asynchronous but is there an other way to do the request and receive my json well ?
Thank you
© Stack Overflow or respective owner