当前位置: 代码迷 >> 综合 >> Unity ipv6的兼容适配(iOS) Scoket
  详细解决方案

Unity ipv6的兼容适配(iOS) Scoket

热度:103   发布时间:2023-11-05 17:26:58.0

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群


做了一个产品,在ios审核上架的时候biej被拒了如下:

Guideline 2.1 - Performance - App Completeness


We discovered one or more bugs in your app when reviewed on iPhone running iOS 11.4.1 on Wi-Fi connected to an IPv6 network.
Specifically, when we tapped on the log in button, no further action took place.

意思是说应用在ipv6的环境下不能登录。

然后我们就要找解决方案了:

之前的scoket连接建立,AddressFamily.InterNetwork是ipv4的网络

     /// <param name="port">端口号</param>public void CreateConnection(string serverAddress, int port){if (scoket != null && scoket.Connected){return;}try{this.scoket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);this.scoket.NoDelay = true;IPEndPoint end_point = new IPEndPoint(IPAddress.Parse(serverAddress), port);this.scoket.BeginConnect(end_point, new AsyncCallback(this.Connected), this.scoket);}catch (Exception e){Debuger.Log( e.Message);}}

我们需要检测当前网络环境类型并做兼容处理如下

   /// <param name="port">端口号</param>public void CreateConnection(string serverAddress, int port){if (scoket != null && scoket.Connected){return;}try{IPAddress[] address = Dns.GetHostAddresses(serverAddress);if (address[0].AddressFamily == AddressFamily.InterNetworkV6){Debug.Log("Connect InterNetworkV6");scoket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);}else{Debug.Log("Connect InterNetwork");scoket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);}this.scoket.NoDelay = true;IPEndPoint end_point = new IPEndPoint(IPAddress.Parse(serverAddress), port);this.scoket.BeginConnect(end_point, new AsyncCallback(this.Connected), this.scoket);}catch (Exception e){Debuger.Log( e.Message);}}

 IPAddress[] address = Dns.GetHostAddresses(serverAddress);我们可以知道当前网络环境类型,然后创建对应连接的scoket

以上对ipv6的网络适配有一个前提就是 服务器也必须能支持ipv6的网络传输不然一切都是空谈

点击这里 了解如何配置ipv6的测试环境https://blog.csdn.net/qq_37310110/article/details/81905709


 

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群

 

  相关解决方案