我必须在背景模式下使用NSOPeration内部的异步NSURLConnection,因为它的响应具有大数据量,我必须避免苹果的有限长度编码在didEnterBackground中使用。相反,我通过NSOperation使用下面的代码和NSInvocation,但它不是working.connectToServer是否有NSURLConnection操作?请帮助吗?didReceiveData,didReceiveResponse委托方法是不是被调用?使用NSInvocation的NSOperation内的异步NSURLConnection?
-(void)viewDidLoad
{
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(connectServer)
object:nil];
[queue addOperation:operation];
[operation release];
[queue autorelease];
}
-(void)connectServer
{
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
if(theConnection)
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
}
}
[异步NSURLConnection与NSOperation](http://stackoverflow.com/questions/9223537/asynchronous-nsurlconnection-with-nsoperation) – 2012-02-10 10:39:13
的可能重复是connectServer方法被调用? – 2012-02-10 10:43:03