我想NSURLConnection
在后台模式下做,因为它的响应有很多数据。论坛告诉使用 Apple 的有限长度编码在didEnterBackground
. 但我想避免它。而不是它,我通过 as 使用以下代码NSOperation
,NSInvocation
但它不起作用。connectToServer
正在NSURLConnection
手术中。有什么帮助吗?didReceiveData
,didReceiveResponse
委托方法不被调用?
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(connectToServer)
object:nil];
[queue addOperation:operation];
[operation release];
[queue autorelease];
-(void)connectToServer
{
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");
}
}