开发者

NSNotificationCenter and ASIHTTPRequest

I hope to get the http header info(file size) in asynchronous mode.

开发者_运维问答

So I initialize as codes:

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

my codes to read the http header

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


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

}

It has to change the source code of ASIHTTPRequest.m

I did add my codes in function readResponseHeaders to notify the event is triggered )

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

}

the log file reports:

2010-05-15 13:47:38.034 myapp[2187:6a63] *** -[NSConcreteNotification contentLength]: unrecognized selector sent to instance 0x46e5bb0

Welcome any comment

Thanks interdev


NSNotificationCenter's observers' selector must have one of the signatures:

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

It cannot be an ASIHTTPRequest (even if you put ASIHTTPRequest* in the argument, it is still an NSNotification.)

There are 3 properties of NSNotification: name, object and userInfo. You could obtain the ASIHTTPRequest with object, if self is an ASIHTTPRequest when you post that notification:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜