简体   繁体   中英

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];
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM