Search Unity

Unity 4.6.2 compile with IL2CPP, .net C# threads

Discussion in 'Scripting' started by SteeBono, May 29, 2015.

  1. SteeBono

    SteeBono

    Joined:
    Apr 4, 2015
    Posts:
    11
    Hi guys,

    I updated Unity from version 4.6.1 to 4.6.2 in order to compile my game for iOS 64-bit.
    All builds are successfully concluded without errors.
    But now it seems that the thread no longer work.
    Use a thread to check if the user is connected to internet with this code:

    Code (CSharp):
    1.  
    2. private void CheckForInternetConnection()
    3. {
    4.       System.Threading.Thread.Sleep(1000);
    5.       try
    6.       {
    7.             using (WebClient client = new WebClient())
    8.             using (System.IO.Stream stream = client.OpenRead("http://www.google.com/"))
    9.             {
    10.                  Debug.LogWarning("Online");
    11.                  connected = true;
    12.             }
    13.        }
    14.        catch
    15.        {
    16.               Debug.LogWarning("Offline");
    17.               connected = false;
    18.        }
    19.     }
    20.  
    This code works well with iOS 32 bit, Android and so on, but it doesn't work with iOS 64 bit.

    So.. How can I fix this problem?
    And IL2CPP has some problem with .net threading and WebClient?

    Thanks guy!
     
  2. SteeBono

    SteeBono

    Joined:
    Apr 4, 2015
    Posts:
    11
    I have found a solution!
    With Unity 4.6.2 you can not use WebClient because it is not implemented on IL2CPP yet.
    Unity say:
    WebRequest/WebClient API is currently available but not functioning. Anything requiring asynchronous sockets through Delegate BeginInvoke/EndInvoke currently doesn’t function. We will address this in an upcoming patch release.

    With Unity 4.6.4 it works!
    Fixes:
    • iOS/IL2CPP: Added support for WebRequest to HTTPS addresses when using the Api Compatibility Level setting of .NET 2.0 Subset.
    • iOS/IL2CPP: Corrected a number of problems related to WebRequest and ThreadPool interaction.
    • iOS/IL2CPP: Fixed a queuing bug that might lead to WebRequests arriving at the same time and being used incorrectly.
    • iOS/IL2CPP: Fixed WebRequests getting stuck in socket polling stage when the stage should be skipped.
    Admin you can close thread.