2010-05-13 46 views
0

在我的一個項目中,我希望使用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); 
} 

回答

1

也許請求失敗?你只是實現協議的成功方法 - 請求:didFailLoadWithError:取而代之的調用?

我會執行every method possible只是爲了調試,看看發生了什麼。然後,當你有它的工作,刪除你不需要的onls。

但是,您應該始終檢查錯誤 - 您可能必須告訴用戶Apple已經失敗以允許應用程序進入應用程序商店!即使你不必告訴用戶,你也應該做點什麼!

+0

嗨院長,感謝您的回答,我試圖實現所有委託方法作爲測試目的,但沒有一個被調用。即使使用http或https,也沒有區別。它只是沉默。 – 2010-05-27 10:56:12

+0

如果您嘗試使用「http://www.google.com」作爲網址,會發生什麼情況?這應該肯定會給出迴應! – deanWombourne 2010-05-27 11:13:27

+0

謝謝Dean,這是我的錯。該請求確實收到錯誤,所以它詢問委託 - (void)請求:(TTURLRequest *)請求didFailLoadWithError:(NSError *)錯誤。我一直認爲請求網址是正確的,最近服務器發生了變化。一些很好的注意事項:如果你重寫了超級委託方法,那麼你應該使用[super didDOsth]方法調用父進程來實現所有的錯誤處理方法。 – 2010-05-28 10:37:32