I have a "WebAPI" class that handles all web API calls, the class uses NSURLConnection through its delegate-based asynchronous calls.
Whenever an object needs to interact with the web API, it will use the WebAPI instance and call the required method, as shown below, in case of login. I make the following call from AppDelegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
WebAPI *webAPI = [[WebAPI alloc] init];
[webAPI performLoginWithUserName:@"test1@myserver.com" andPassword:@"password"];
}
The problem is that after calling executeLoginWithUserName: andPassword, the code progresses, and any / all response is received in the delegate methods that are implemented in WebAPI.m.
This is a real problem, because I need to be able to get response codes and any data received in the class method where the call came from in WebAPI. I would like to be able to:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
WebAPI *webAPI = [[WebAPI alloc] init];
WebAPIResponse * webAPIRespnse = [webAPI performLoginWithUserName:@"test1@myserver.com" andPassword:@"password"];
}
Where the WebAPIResponse class is a custom class that will contain the HTTP status code and any received data.
This can be done if I change WebAPI.m to use NSURLConnection sendSynchronousRequest, but this does not allow me to receive all HTTP codes.
What would be the best way to fulfill this requirement?
Thank you for your help.
source
share