首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSNotificationCenter和ASIHTTPRequest

NSNotificationCenter和ASIHTTPRequest
EN

Stack Overflow用户
提问于 2010-05-15 13:52:32
回答 1查看 795关注 0票数 0

我希望在异步模式下获得http头信息(文件大小)。

所以我初始化为代码:

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processReadResponseHeaders:) name:@"readResponseHeaders"
                                           object:nil];

我读取http头的代码

代码语言:javascript
复制
-(void)processReadResponseHeaders: (ASIHTTPRequest *)request ;//(id)sender;
{


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

}

它必须更改ASIHTTPRequest.m的源代码

我确实在函数readResponseHeaders中添加了代码,以通知事件已被触发)

代码语言:javascript
复制
- (void)readResponseHeaders
{
     //.........................
    [[NSNotificationCenter defaultCenter]  postNotificationName:@"readResponseHeaders"  object:self];//

}

日志文件报告:

2010-05-15 13:47:38.034 myapp2187:6a63 * -NSConcreteNotification contentLength:无法识别的选择器发送到实例0x46e5bb0

欢迎您的评论

感谢interdev

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-15 14:17:20

NSNotificationCenter的观察者选择器必须具有以下签名之一:

代码语言:javascript
复制
-(void)observe;
-(void)observeWithNotification:(NSNotification*)notification;

它不能是ASIHTTPRequest (即使在参数中放入ASIHTTPRequest*,它仍然是NSNotification)。

NSNotification有3个属性:nameobjectuserInfo。当您发布该通知时,如果self是ASIHTTPRequest,则可以使用object获取self

代码语言:javascript
复制
-(void)processReadResponseHeaders:(NSNotification*)notification {
    ASIHTTPRequest* request = [notification object];
    unsigned long long contentLength = [request contentLength];
    ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2839086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档