Jump to: navigation, search

Unity Network Fix

Recently we have discovered an issue on Unity that causes the network stack in Unity (eg the Unity-provided networking libraries) to stop functioning. This is a problem with the Unity game engine itself and Unity has provided a workaround by modifying the produced source code:

In the generated XCode project, in Classes/Unity/WWWConnection.mm

Inside extern "C" void UnitySendWWWConnection:

Replace the following lines (348 to 357):

// Start connection on non-main thread
// This is important because didReceiveData handler may stall in case a target buffer is not ready.
// We have limited accumulator buffer pretty much for everything (assetbundles, downloadhandler) and stall until the data is consumed.
[queueToUse addOperation:[NSBlockOperation blockOperationWithBlock:^{
NSRunLoop *loop = [NSRunLoop currentRunLoop];
delegate.connection = [[NSURLConnection alloc] initWithRequest:request delegate:delegate startImmediately:NO];
[delegate.connection scheduleInRunLoop:loop forMode:NSRunLoopCommonModes];
[delegate.connection start];
[loop run];
}]];

With these:

delegate.connection = [[NSURLConnection alloc] initWithRequest: request delegate: delegate startImmediately: NO]; 
[delegate.connection setDelegateQueue: queueToUse]; 
[delegate.connection start];