NSURLConnection连接:didReceiveData:未在ios5上调用 [英] NSURLConnection connection:didReceiveData: is not called on ios5

查看:128
本文介绍了NSURLConnection连接:didReceiveData:未在ios5上调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个奇怪的问题。
我想从网上加载图片,所以我使用NSURLConnection来做。
当我在ios4.3上测试我的代码时一切正常。
但是当我在ios5.0上启动我的应用程序时,我发现连接:didreceiveData没有被调用,无论我做了什么。正常调用
otherelse函数,就像ios4.3中的connectionDidFinishLoading和ios5.0中的connectionDidFinishDownloading一样。
所以你们,谁能帮助我,谢谢高级!

A weird problem. I wanna load an image from web, so i use NSURLConnection to do it. Everything is ok when i do testing my code on ios4.3. But when i'm launch my app on ios5.0, i found the connection:didreceiveData haven't been called whatever what i did. otherelse functions is called normally, just like connectionDidFinishLoading in ios4.3 and connectionDidFinishDownloading in ios5.0. so u guys, who can help me, thanks advanced!

-(void)load
{
    if(isDownloading){
        return;
    }
    if(conn != nil){
        [conn release];
    }
    if(data != nil){
        [data release];
        data = nil;
    }
    [self isDownloading:YES];
    ImageDownloadData* imageDownloadData = [imageList objectAtIndex:count];
    NSURL* url = [imageDownloadData url];
    NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    if(conn){
        [conn start];
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)rd
{
    NSLog(@"data");
    if(!data){
        data = [[NSMutableData alloc] initWithData:rd];
        return;
    }
    [data appendData:rd];
}


推荐答案

我无法确定如果这是你遇到的同样的问题,但我遇到了类似的问题,并通过取出in方法和对 NSURLConnectionDownloadDelegate 的引用来解决它。显然, NSURLConnection 的代表只能实现一次从 NSURLConnectionDelegate 派生的两个协议之一。

I can't be sure if this is the same problem you're having, but I had a similar issue, and resolved it by taking out the in methods and references to NSURLConnectionDownloadDelegate. Apparently delegates of NSURLConnection can only implement one of the two protocols that are derived from NSURLConnectionDelegate at a time.

在4.3和5.0之间有一些奇怪的API变化。 Apple将NSURLConnectionDelegate从非正式协议更改为正式协议,并将一些方法扩展为另外两个子协议: NSURLConnectionDataDelegate NSURLConnectionDownloadDelegate 。 (奇怪的是,他们贬低了NSURLConnectionDelegate中的相同方法,但没有记录他们搬到的地方。)

There's been some odd API changes between 4.3 and 5.0. Apple changed the NSURLConnectionDelegate from an informal protocol to a formal one, and branched out some of the methods into two additional subprotocols: NSURLConnectionDataDelegate and NSURLConnectionDownloadDelegate. (Oddly though, they depreciated the identical methods in NSURLConnectionDelegate but didn't document where they moved to.)

我一直在注意何时针对6.0 API编译我的代码我一直无法让Cocoa Touch调用连接:didReceiveData:如果我实现了来自 NSURLConnectionDataDelegate 的方法, NSURLConnectionDownloadDelegate 。我实现的所有其他方法都按预期调用。

I've been noticing when compiling my code against the 6.0 API that I've been having trouble getting Cocoa Touch to call connection: didReceiveData: if I Implement methods from both NSURLConnectionDataDelegate and NSURLConnectionDownloadDelegate. All the other methods I implemented were called as expected.

这篇关于NSURLConnection连接:didReceiveData:未在ios5上调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆