在我的应用程序中,我有ViewControllers->业务逻辑层(BLL) - >数据访问层(DAL) - >(HttpApi)或(SQLiteApi)
在我的HttpApi类中,我使用带有异步请求的ASIHttpRequest。
请求最初来自ViewController,一直到上面的层。
我希望能够将Async请求的结果“注入”回到此链中,以便它可以一直返回到ViewController并在途中由中间层处理。
我感觉这是我需要的代表,但我不确定要实施什么。
编辑: 我想我可能需要开发一个从HTTPAPI一直回到视图控制器的回调链。我需要使用委托。
因此,视图控制器符合BLL委托,BLL符合DAL代表等等。
答案 0 :(得分:4)
我会在收到使用通知的回复后广播请求
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestFinished" object:request];
然后你的任何课程都可以听如下:
[[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);
}
}