My Apple AppStore application was rejected for not supporting IPv6 networks.
Here is declaration of my server URL for WebClient. "ipv4" is IPv4 address of server. I didn't add it here to stay secure.
RemoteServerConnector.Instance.DefaultServerUrl = "http://ipv4/api.php";
Then I have this method to check connection:
private class MyWebClient : WebClient {
public int timeOut { get; set; }
protected override WebRequest GetWebRequest(Uri address) {
WebRequest w = base.GetWebRequest(address);
w.Timeout = timeOut;
return w;
}
}
public bool checkInternetConnection() {
try {
using(MyWebClient client = new MyWebClient()) {
client.timeOut = ApiUrls.RemoteServerConnectorTestTimeout;
var removeString = "api.php";
var testHttp = DefaultServerUrl.EndsWith(removeString) ? DefaultServerUrl.Remove(DefaultServerUrl.Length - removeString.Length, removeString.Length) : DefaultServerUrl;
using(client.OpenRead(testHttp)) {
return true;
}
}
} catch(WebException ex) {
return ex.Status != WebExceptionStatus.ConnectFailure;
} catch(Exception ex) {
return false;
}
}
It always throw exception in IPv6 networks. I already tried this solution Xamarin iOS IPv6 App Store Rejection, but it doesn't work. I also tried to add IPv6 instead of IPv4 in variable DefaultServerUrl. I also tried http://ipv6/api.php and also http://[ipv6]/api.php
Can't find any solution for this type of connection (WebClient). I found only other solutions with TCP/IP protocol and I don't want to change it in my app.
I also saw Xamarin blog about IPv6, but I don't know what to do. Couldn't add link to it, because of permissions.
What should I change in my code to make it working? Thank you for your time :)
As I tried almost everything and it didn't work I checked settings of customers server. There was not settings for IPv6. We fixed it and now it is working with with ModernHttpClient. I switched in app from IPv4 address to hostname.
My code for ModernHttpClient.
var handler = new NativeMessageHandler();
using (var client = new HttpClient(handler))
{
client.Timeout = TimeSpan.FromMilliseconds(ApiUrls.RemoteServerConnectorTestTimeout);
var removeString = "api.php";
var testHttp = DefaultServerUrl.EndsWith(removeString) ? DefaultServerUrl.Remove(DefaultServerUrl.Length - removeString.Length, removeString.Length) : DefaultServerUrl;
using (client.GetAsync(testHttp).Result)
{
return true;
}
}