且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS中在后台运行NSURLConnection

更新时间:2023-01-05 12:57:54

Ranjit:根据您在不同响应中的评论,我怀疑您是从主线程发送第一个请求.收到第一个响应后,您将在后台对其进行处理,然后也从后台发送第二个请求.后续请求应从主线程发送

Ranjit: Based on your comments in the different responses, I suspect you are sending the 1st request from the main thread. When you receive the 1st response, you process it in the background, and then send the 2nd request also from the background. The subsequent requests should be sent from the main thread

[self performSelectorOnMainThread:@selector(myMethodToOpenConnection:)
                       withObject:myObject
                    waitUntilDone:NO];

否则,线程将在调用委托之前退出

otherwise the thread exits before the delegate is called