Unity iOS and IPv6 support

Apple recently announced that beginning June 1, 2016, “all apps submitted to the App Store must support IPv6-only networking.” Since many of our users publish Unity games to the App Store, we wanted to take a moment to discuss Unity’s support for IPv6-only networks. Note that this requirement applies to both new app submissions and updates to existing apps.

What is IPv6?

From the Wikipedia article: “Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet.” Devices can operate on an IPv4-only network (the previous standard), and IPv6-only network, or a network with both protocols in use. Apple’s new requirement means that apps must be able to operate in an IPv6-only network.

It is important to understand that IPv4 and IPv6 networks do not interoperate, although it is possible to pass traffic from one type of network over the other with tunnelling.

Does Unity support IPv6?

Yes! WWW and UnityWebRequest are IPv6 compatible on iOS out of the box because they are based on high level Apple networking APIs. And over the past few months we have been working to bring support for IPv6-only networks to Unity’s .NET/IL2CPP libraries. Our last known IPv6 bugs related to .NET/IL2CPP were corrected in the 5.3.4p4 patch release. There is one fix pending for UNET which is going to be shipped in coming weeks. Thanks to help from great members of our community (like Exit Games) we have been able root out a number of bugs in the Unity Engine code and provide support for IPv6-only networks on the following platforms:

  • Editor: All platforms
  • Standalone player: All platforms
  • iOS
  • Android

We’ll continue to add support for IPv6-only networks on other platforms in the future.

What about older versions of Unity?

If you are using only WWW or UnityWebRequest APIs to access network resources you should be fine, though please test your games carefully.

We are also planning to backport our .NET/IL2CPP fixes to selected older lines of Unity and release them as 4.7.2, 5.1.5 and 5.2.5 updates.

What should you do?

First, test your game in IPv6-only setup to assess if all the game features work as intended. This guide from Apple goes through the setup of an IPv6-only testing network using a Mac with OS X 10.11 or later. This is the same testing that App Store reviewers will use, so it is a good place to start with IPv6 testing. Since IPv4 and IPv6 networks cannot interoperate, you must test on an IPv6-only network to ensure everything is working well. If your device has both IPv6 and IPv4 addresses, then socket operations could succeed using IPv4.

Second, audit your code for a few indicators of possible problems:

  • Look for the use of IPv4 addresses (e.g. 127.0.0.1, 8.8.4.4). Any use of such hardcoded addresses should be removed. Prefer host names, which can be used to look up the proper IPv4 or IPv6 address of a given device for the proper type of network.
  • Look for the use of the IPAddress.AddressFamily property. If the code branches based on the value of the property, is there a branch that handles IPv6 properly?
  • Look for the use of the IPAddress.Any and IPAddress.Loopback fields. These fields work with IPv4 addresses, not IPv6 addresses. Use the IPAddress.IPv6Any and IPAddress.IPv6Loopback fields as well to ensure IPv6 support.

If you encounter troubles beyond the ones mentioned above, please make sure you are using a build with the necessary fix in it. If a fix has not yet landed in your line (4.7.x, 5.1.x, 5.2.x), wait until we have released a patch with it. Then proceed to upgrade to this version.

Some of 3rd party native and managed networking plugins might also be not compatible with IPv6 networks, please consider reaching out plugin vendor for their compatibility status.

Finally, let us know if you encounter bugs in Unity related to IPv6. We will work hard to correct them as soon as possible. I’ll be hanging out there to help.

P.S. this is mirror re-post of our blog post: Unity Blog

Update: 4.7.2 is live now http://unity3d.com/get-unity/download/archive
Update #2: 5.2.5 is live too: http://unity3d.com/get-unity/download/archive (scroll down below 5.3.x updates).
Update #3: 5.1.5 is live too: http://unity3d.com/get-unity/download/archive (scroll down below 5.2.x updates).

We use the Ping class to test network connectivity. Documentation of this doesn’t seem to indicate support for IPv6 as the method refers to the address in dot notation, nor does a quick test of swapping out IPv6 addresses for IPv4 ones.

Thank you for bringing this to our attention! We are having our internal discussions if this class will support that. At the moment I would recommend to use other ways to detect internet connectivity.

How soon will you have a response on that? Ping was far more reliable in checking connectivity than WWW, as we weren’t concerned with any delay in DNS resolution.

No ETA at the moment. We are still looking what we can do about it. If you are in hurry I would recommend falling back to WWW method.

Quick update on Ping class, we aiming to fix it for 5.3 and up, unfortunately it won’t make to older Unity versions.

Hi,

We went through reworking all our networking interfaces (we used to use classic http requests for backend server com and socket connections for asset download) we swapped everything with UnityWebRequest, DownloadHandler and UploadHandler from UnityEngine.Experimental.Networking

Everything works fine on Editor and android but for iOS it just … crashes.

We are using : Unity 5.3.5p2
xCode 7.2
and iPad2 with iOS 9.3.2
Build settings :

  • IL2CPP
  • Universal Architecture (min iOS 7.1)
  • API Level .Net 2.0
  • Strip Engine code set to OFF
  • AOT-Compile options set to : mint-trampoline 512 (we were using this for mono scripting backend)

On Xcode :

  • Bitcode is disabled
  • optimisation level set to (for release and debug) : None[-O0]

Here is the error we get on console when the game runs :

Unable to find method GetProgress in [UnityEngine.dll]UnityEngine.Experimental.Networking.DownloadHandler
.
.
Unable to find method ReceiveContentLength in [UnityEngine.dll]UnityEngine.Experimental.Networking.DownloadHandler
.
.
[project name] was compiled with optimization - stepping may behave oddly; variables may not be available.

When we build with mono as scripting backend things work fine. But IL2CPP is mandatory for us.
Thank you for your help.

@beQr86

It sounds like these methods might be getting stripped from the managed code in UnityEngine.dll. Note that even with Engine Code Stripping disabled, the IL2CPP build toolchain will still attempt to strip code from managed assemblies. You can use a link.xml file to preserve everything in the UnityEngine.dll assembly though:

You can find more details about the link.xml file here: http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html

Thank you for your answer. We will run test with this solution and let you know. We ll also give a look at the current beta version of Unity.

thank you for your help, the first thing that we tested is updating Unity to the beta version 5.4.0b21 and that actually solved the problem. We are going to try the link solution because we prefer staying on a stable unity version.
Will let you know as well

Adding to the link xml file did the trick ! Thank you. We are now going to try to optimize this by re-enabling the engine code stripping and being more specific in the link file with specifiying the type range we wich to exclude from the stripping process.

EDIT :

The final solution we applied was to keep the code stripping classic and specifically signal type that we want to save in the link.xml file. So we added this to the link file :

Thanks again for the help.

1 Like

Hey there, this is Ethan from Mechanist Games. We had a serious problem when dealing with Apple’s new requirement for IPV6 compatibility. Here is the situation:

new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

With above line of codes, we didn’t see any error generated when running with native C# project and it can be connected to the server properly, it works good with Unity 5.3.5 testing too. But when it comes to Unity 4.7.2 (what we are currently using for our projects), we keep getting popped up error “socketexception” - address that incompatible with requested protocol.

Is there anyone who encountered the same problem? How could we resolve it without upgrading to the latest 5.3 version as it will cost too much of our time to do so, we are now having several ready-to-submit builds waiting for a solution. Thanks in advance!

1 Like

Please submit a bugreport and share your case number.
Thanks!

We are in a really big hurry, what is the fastest way to make Unity aware of the bug?

Where can I submit the bugreport? Haven’t done this before, thanks!

In Unity editor Help menu, pick “Report a bug…”. Once you receive confirmation message, just send me your case number.

Cool, thanks, on it!

There you go: Case 804914, please help push, thanks a bunch!

@CoS_Ethan

Can you let us know the full call stack for the exception? That might help us understand the cause of the problem. Thanks!

Just had them attached, please let me know if this helps.

2675876--188947--screenshot.png
2675876--188948--screenshot1.png