【发布时间】:2012-03-02 16:07:27
【问题描述】:
我想在后台模式下做NSURLConnection,因为它的响应有很多数据。论坛告诉使用Apple的有限长度编码在didEnterBackground中使用。
但我想避免它。而不是它,我通过NSOperation 和NSInvocation 使用以下代码,但它不起作用。connectToServer 有NSURLConnection 操作。请帮助?didReceiveData,@987654328 @delegate 方法没有被调用?
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");
}
}
【问题讨论】:
-
请看我编辑的问题?
标签: objective-c ios nsurlconnection nsoperation nsinvocation