June 21st, 2016

Making Your iOS Apps IPv6 Ready

James Montemagno
Principal Manager, Tech PM

On June 1, Apple started enforcing a new policy whereby all iOS applications must support IPv6-only network services in iOS 9. While Apple states that most apps will not need to be changed or updated, your app may be using a few libraries that need to be updated before you submit your next update.

NetworkFrameworks

Issues and Fixes

Here are some of the most common issues that you may have lingering in your code and how to fix them.

Hard Coded IP Addresses

All newly created IP Addresses will need to be IPv6 or converted to IPv6 if available. Our recommendation is to always use the hostname when possible, but if you are not able to, don’t fear, because it’s super simple with the .MapToIPv6() extension method. This is more of a quick fix, as you’ll never get a pure IPv6 connection; in this case you could also manually convert any IP to a byte array, or simply use IPAddress’s TryParse method to parse any IPv6 address. Additionally, check out some of the nifty methods in System.Net.Dns that can help resolve the IP Address for you if IPv6 is available or not. If you are using HttpClient, BasicHttpBinding, or WebRequests there are no changes needed unless using hard coded IP addresses as discussed above.

There may, of course, be certain older devices that can’t update to support IPv6 and as a developer you are forced to connect using IPv4. If you are stuck in this situation, you’ll have to mention it when submitting your app for review.

Sockets and AddressFamily

When creating .NET Sockets, you’re able to specify the AddressFamily as InterNetworkV6, which will ensure the socket is created using the IPv6 protocol.

Before:

var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

After:

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

Additionally, you can opt not to pass an AddressFamily, in which case Socket will use Dual Mode.

Connectivity Plugin

The Connectivity Plugin for Xamarin and Windows relies on the core reachability sample that Apple created to help developers handle connection state in their app. Since its original release, the reachability sample has been updated and recently the Connectivity Plugin has been updated to be IPv6 compatible. Simply update to the latest release, 2.2.2, and your app will be ready to submit.

Learn More

Be sure to read through the IPv6-only networks announcement from Apple. And their guide on ensuring compatibility with DNS64/NAT64 networks to test an IPv6 network on your Mac.

Author

James Montemagno
Principal Manager, Tech PM

James Montemagno is a Principal Lead Program Manager for Developer Community at Microsoft. He has been a .NET developer since 2005, working in a wide range of industries including game development, printer software, and web services. Prior to becoming a Principal Program Manager, James was a professional mobile developer and has now been crafting apps since 2011 with Xamarin. In his spare time, he is most likely cycling around Seattle or guzzling gallons of coffee at a local coffee shop. He ...

More about author

0 comments

Discussion are closed.