Я хочу сделать NSURLConnection
в фоновом режиме, потому что его ответ имеет много данных.Форумы говорят использовать кодировку конечной длины Apple для использования в didEnterBackground
.
, но я хочу избежать этого.Вместо этого я использую следующий код через 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");
}
}