2010-05-15 36 views
0

我希望以異步模式獲取http頭信息(文件大小)。NSNotificationCenter和ASIHTTPRequest

所以我作爲初始化代碼:

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

我的代碼讀取HTTP頭

-(void)processReadResponseHeaders: (ASIHTTPRequest *)request ;//(id)sender; 
{ 


    unsigned long long contentLength = [request contentLength]; //error occurs here 

} 

它有可能改變ASIHTTPRequest.m

的源代碼

我沒加我代碼功能readResponseHeaders通知事件被觸發)

- (void)readResponseHeaders 
{ 
    //......................... 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"readResponseHeaders" object:self];// 

} 

日誌文件報告:

2010-05-15 13:47:38.034的myapp [2187:6a63] *** - [NSConcreteNotification CONTENTLENGTH]:無法識別的選擇發送到實例0x46e5bb0

歡迎任何評論

感謝 InterDev中

回答

0

NSNotificationCenter的觀察員的選擇必須有一個簽名:

-(void)observe; 
-(void)observeWithNotification:(NSNotification*)notification; 

它不可能是一個ASIHTTPRequest

有NSNotification的3個屬性(即使你把ASIHTTPRequest*的說法,它仍然是一個NSNotification):nameobjectuserInfo

-(void)processReadResponseHeaders:(NSNotification*)notification { 
    ASIHTTPRequest* request = [notification object]; 
    unsigned long long contentLength = [request contentLength]; 
    ... 
} 
+0

KennyTM 非常感謝:當您發佈的通知,你可以得到ASIHTTPRequest與object,如果self是ASIHTTPRequest – arachide 2010-05-15 09:47:10