开发者

ASIHttpRequest send response from ASync request back to view controller

In my app I have got ViewControllers->Business Logic Layer(BLL开发者_运维问答)->Data Access Layer(DAL)->(HttpApi) OR (SQLiteApi)

In my HttpApi class I am using ASIHttpRequest with asynchronous requests.

Requests come from the ViewController initially and all the way up through the above layers.

I would like to be able to "inject" the result from the Async request back into this chain so that it can be returned all the way back down to the ViewController and be processed by the intermediate layers on the way.

I have a feeling that it's Delegates I need but i'm not really sure what to implement.

EDIT: I think I may need to develop a callback chain that goes from HTTPAPI all the way back to the view controller.. I'll need to use delegates.

So, view controller conforms to BLL delegate and BLL conforms to DAL Delegate and so on..


I would broadcast the request upon receiving a response using a notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"requestFinished" object:request];

Then any of your classes can listen as follows:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestFinished:) name:@"requestFinished" object:nil];

- (void)requestFinished:(NSNotification*)notification {
    ASIHTTPRequest *request = (ASIHTTPRequest*)[notification object];

    if ([[[request URL] absoluteString] isEqualToString:expectedURL]) {
        NSString *responseString = [request responseString];
        NSLog(@"RESPONSE %@", responseString);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜