我希望在异步模式下获得http头信息(文件大小)。
所以我初始化为代码:
[[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 myapp2187:6a63 * -NSConcreteNotification contentLength:无法识别的选择器发送到实例0x46e5bb0
欢迎您的评论
感谢interdev
发布于 2010-05-15 14:17:20
NSNotificationCenter的观察者选择器必须具有以下签名之一:
-(void)observe;
-(void)observeWithNotification:(NSNotification*)notification;它不能是ASIHTTPRequest (即使在参数中放入ASIHTTPRequest*,它仍然是NSNotification)。
NSNotification有3个属性:name、object和userInfo。当您发布该通知时,如果self是ASIHTTPRequest,则可以使用object获取self:
-(void)processReadResponseHeaders:(NSNotification*)notification {
ASIHTTPRequest* request = [notification object];
unsigned long long contentLength = [request contentLength];
...
}https://stackoverflow.com/questions/2839086
复制相似问题