我必须在后台模式下在 NSOPeration 中使用 Asynchrnous NSURLConnection,因为它的响应有大数据我必须避免在 didEnterBackground 中使用 Apple 的有限长度编码。而不是它,我通过 NSOperation 使用以下代码和 NSInvocation 作为,但它不起作用。 connectToServer 正在进行 NSURLConnection 操作。请问有什么帮助吗?didReceiveData,didReceiveResponse 委托方法没有被调用吗?
-(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");
}
}
}