Xamarin iOS IPv6 App Store Rejection

2019-02-26 02:59发布

问题:

We have been building a iOS app that is about Client - Server App. We are using an SQL connection and WCF web services in the iOS app with Xamarin.

SQL Connection Code :

    String ips = "10.0.0.1" ; //Example.
  SqlConnection con =   new SqlConnection(@"Data Source=" + ips + "; initial Catalog="x";user id =y;password = z;");

Apple decided to use only ipv6 on iOS9, so they published a document about IPv6 compatibility - IPv6 Documentation

Xamarin published a blog post about this too - Making Your iOS Apps IPv6 Ready

I read all those documents, but I could not manage to get rid of this "Store Rejection" problem.

I want to show you my last attemp : (ipv4 to ipv6)

string input = "10.0.0.1";
            string ips = "";
            IPAddress address;
            if (IPAddress.TryParse(deviceIP, out address))
            {
                switch (address.AddressFamily)
                {
                    case System.Net.Sockets.AddressFamily.InterNetwork:
                        // we have IPv4
                        ips = input;
                        break;
                    case System.Net.Sockets.AddressFamily.InterNetworkV6:
                        // we have IPv6
                        IPAddress ip = IPAddress.Parse(input).MapToIPv6();
                        ips = "[" + ip.ToString() + "]";
                        break;
                    default:
                        //
                        break;
                }
            }

I used the MapToIPv6() function as described in the Xamarin blog post, but again my app was rejected by Apple.

Our app works well on IPv4 (Apple says this too). When Apple engineers turn off ipv4 and only use ipv6, our app could not reach the host.

Please help me to resolve this problem.

Platform : Visual Studio 2015 with Xamarin on Windows 10 + Mac OS X El-Capitan

Server : ON IPv4 Only.

回答1:

There's already some helpful stuff in the comments, but I think that your main problem is that you had the IPv4 to IPv6 mapping the other way around. You were leaving the IPv4 address as it was and mapping the IPv6 address to IPv6 which it already was.

Take a look at the fixed version:

string input = "10.0.0.0";
string ips = "";
IPAddress address;
if (IPAddress.TryParse(input, out address))
{
    switch (address.AddressFamily)
    {
        case System.Net.Sockets.AddressFamily.InterNetwork:
            // we have IPv4, map it to IPv6
            IPAddress ip = IPAddress.Parse(input).MapToIPv6();
            ips = ip.ToString();
            break;
        case System.Net.Sockets.AddressFamily.InterNetworkV6:
            // we have IPv6, leave it as is
            ips = input;
            break;
    }
}

To see for yourself, you can take a look at the Reference Source. From there you see that in your example the AddressFamily was InterNetworkV6 so the MapToIPv6 method just returns the IPAddress unchanged because there's nothing to change.

public IPAddress MapToIPv6()
{
    if (AddressFamily == AddressFamily.InterNetworkV6)
    {
        return this;
    }

    // ...
}


回答2:

Change your server IP: 10.0.0.0 to the domain name, such as db.test.com, it's Apple's recommended approach.

string input = "db.test.com";
IPAddress[] ads = Dns.GetHostAddresses (input);
string ips = ads[0];


回答3:

Have it resolved? You shouldn't care about AddressFamily of device,just care about remote ip AddressFamily . IPAddress ip = IPAddress.Parse(input); Socket s = new Socket (ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); I used it, and it works.