我有这种方法:
-(void)updateSomething
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *url = [NSURL URLWithString:@"some url"];
ASIFormDataRequest *httpRequest = [ASIFormDataRequest requestWithURL:url];
[httpRequest startSynchronous];
//some other stuff
[pool drain];
}
我在
applicationDidFinishLaunching
上调用此方法如果我在主线程上调用它就可以正常工作
[self getMyItems];
但是,当我在单独的线程上调用它时,会收到“程序接收到的信号:“EXC_BAD_ACCESS”
[self performSelectorInBackground:@selector(getMyItems) withObject:nil];
任何想法如何解决这个问题?
最佳答案
当可以使用ASINetworkQueue时,为什么要在单独的线程上执行单独的请求?
ASINetworkQueue *aQueue = [[ASINetworkQueue alloc] init];
[aQueue addOperation:requestToAdd];
[aQueue setDelegate:self];
[aQueue setRequestDidFinishSelector:@selector(requestFinished:)];
[aQueue setRequestDidFailSelector:@selector(requestFailed:)];
[aQueue setQueueDidFinishSelector:@selector(queueFinished:)];
[aQueue go];
ASINetworkQueue
是NSOperationQueue
的子类,ASI * Request在单独的线程上运行。关于iphone - iPhone-ASIHTTPRequest线程安全吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5826383/