A
A
Anton Petrov2014-01-06 16:27:32
Objective-C
Anton Petrov, 2014-01-06 16:27:32

How to get response from server using AFNetworking (Obj-C)?

I decided to deal with AFNetworking and created a simple console application that contains only one POST request of this kind:

AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager POST:@"http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
}];

After starting the project, NSLog does not output anything to the console. Help me figure out what the problem is.
My simple app

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
deleted-mezhevikin, 2014-01-06
@itsmepetrov

The problem is that when return 0; is called; in the main function, the application terminates. And since in afnetworking the request is asynchronous, it simply does not have time to work.
Make an application with one controller / window and paste the code there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question