不调用的代理函数Three20 url请求模型
问题描述:
在我的一个项目中,我希望使用TTURLRequestModel通过将TTURLXMLResponse传递给请求来填充XML格式的响应数据。但是,委托方法永远不会被调用。有人能告诉我我在这两个文件中缺少的东西吗?我是否需要初始化库的其他元素?不调用的代理函数Three20 url请求模型
Three20Parser.h
@interface Three20Parser : TTURLRequestModel{
}
- (void) download;
@end
Three20Parser.m
#import "Three20Parser.h"
#import "extThree20XML/extThree20XML.h"
@implementation Three20Parser
- (id)init{
self = [super init];
return self;
}
- (void) download{
NSString *requestURL = @"http://server.local/service.asmx";
NSLog(@"requestURL: %@", requestURL);
TTURLRequest *request = [TTURLRequest requestWithURL:requestURL delegate:self];
request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER;
request.cachePolicy = TTURLRequestCachePolicyNone;
TTURLXMLResponse *response = [[TTURLXMLResponse alloc] init];
request.response = response;
TT_RELEASE_SAFELY(response);
[request send];
}
/*
the requestDidFinishLoad is not called.
*/
- (void)requestDidFinishLoad:(TTURLRequest *)request{
//TTURLXMLResponse *response = request.response;
//NSLog(@"response: %@", [[NSString alloc] initWithData:response.data encoding:NSUTF8StringEncoding]);
NSLog(@"REQUEST DID FINISH", nil);
}
答
也许请求失败?你只是实现协议的成功方法 - 请求:didFailLoadWithError:取而代之的调用?
我会执行every method possible只是为了调试,看看发生了什么。然后,当你有它的工作,删除你不需要的onls。
但是,您应该始终检查错误 - 您可能必须告诉用户Apple已经失败以允许应用程序进入应用程序商店!即使你不必告诉用户,你也应该做点什么!
嗨院长,感谢您的回答,我试图实现所有委托方法作为测试目的,但没有一个被调用。即使使用http或https,也没有区别。它只是沉默。 – 2010-05-27 10:56:12
如果您尝试使用“http://www.google.com”作为网址,会发生什么情况?这应该肯定会给出回应! – deanWombourne 2010-05-27 11:13:27
谢谢Dean,这是我的错。该请求确实收到错误,所以它询问委托 - (void)请求:(TTURLRequest *)请求didFailLoadWithError:(NSError *)错误。我一直认为请求网址是正确的,最近服务器发生了变化。一些很好的注意事项:如果你重写了超级委托方法,那么你应该使用[super didDOsth]方法调用父进程来实现所有的错误处理方法。 – 2010-05-28 10:37:32