In fact, my servers were well but a lot of latency was added to the requests, certainly because my application wasn't responsive enough to handle the requests at full speed. At this moment, I understood something important, asynchronous NSURLConnections are tied to the main runloop in the NSEventTrackingRunLoopMo
Cocoa uses this mode to restrict incoming events during mouse-dragging loops and other sorts of user interface tracking loops.
A simple test to recognize an application using NSURLConnection in its default mode to load there remote images is to scroll the UITableView with your finger to disclose an unloaded image, and to keep your finger pressed on the screen. If the image doesn't load until you release you finger, you've got one (try with the Facebook app for instance). It took me quite some time to understand the reason for this lagging issue.
一般情况下,我们使用NSURLConnection时,都使用如下的代码:
_connection 这段代码创建的connection运行在main runloop以及NSEventTrackingRunLoopMo
_connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self startImmediately:NO];
可以用https://github.com/rs/SDWebImage中的开放框架做个测试。
Cocos will freeze while working with a
//
// If you want to attach the opengl view into UIScrollView
// uncomment this line to prevent 'freezing'. It doesn't work on
// with the Fast Director
//
// [[NSRunLoop currentRunLoop] addTimer:animationTimerforMode:NSRunLoopCommonModes];
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLi
[CCDirector setDirectorType:kCCDirectorTypeNSTimer];
You need to force it to set the director type to kCCDirectorTypeNSTimer to prevent cocos2d from “freezing” while scrolling. Either change
the line in the macro, or copy the macro contents to your appDidFinishLaunching method, and change the line above to simply:
[CCDirector setDirectorType:kCCDirectorTypeNSTimer] ;