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.
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.
0 comments