我必須在背景模式下使用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