Search Unity

TcpClient.Connect() on iOS 14 triggers local network access permissions required.

Discussion in 'iOS and tvOS' started by larku, Nov 5, 2020.

  1. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hi, I'm having an issues on iOS 14 with calls to
    Code (CSharp):
    1. TcpClient client = new TcpClient("some.remote.host.com", 10161)
    is causing a local network permission requirement that reads "App ... would like to find and connect to devices on your local network".

    If the user select "Don't allow" network access is denied and the app can not connect to our remote server.

    I've tested this on both Unity 2019.2.12f1 and 2020.1.11f1 with Xcode 12.1 (12A7403) with the same result on each.

    I was suspicious that it could have been caused by hitting the local DNS server (on local network) but performing a manual
    Code (CSharp):
    1. IPAddress[] serverIPs = Dns.GetHostAddresses(url);
    succeeds without issue and calling
    Code (CSharp):
    1. TcpClient.connect(...)
    with the returned IP address failed with the same issue.

    I understand that iOS 14 has new privacy requirements and permissions are required to access machines on the local network but this should not fall into that category as we're only connecting to remote hosts.

    This is a total show stopper for our networked games.

    Any ideas?
     
    Last edited: Nov 11, 2020
  2. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Anyone else having this issue?

    I'm totally stumped here - any Unity support able to look into this?
     
  3. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Note, I've done more testing and it appears to occur when we use the port number 10161 that our server is listening on. Connecting to port 80 does not trigger this network permission requirement.

    Very frustrating.
     
  4. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    This code will trigger the Local Network Access permissions on iOS 14:

    Code (CSharp):
    1.             IPAddress address = IPAddress.Parse(<add remote ip address here>);
    2.             IPEndPoint endPoint = new IPEndPoint(address, 10161);
    3.             client = new TcpClient();
    4.             client.Connect(endPoint);
     
  5. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    Did you open a bug report for this?
     
  6. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Now that I read the post, We have been experiencing connectivity issues with CloudKit with some betatesters, the error on the exceptions was CKCode 3 which means network not available, even when that user had 4G .
    Im wondering now if this could be the case.
     
  7. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422

    Indeed, unless the user selects to allow local network access we get a "No Route To Host" error.
     
  8. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Yep.
     
  9. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    I'm trying to correlate it with a bug I've found so if you don't mind... Does it happen both connected to wifi and using 3g/4g ?
    Which iOS version is happening with ? 4.0 , 4.0.1 , 4.2 ?

    Thank you very much, please keep us updated about this
     
  10. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    I don't have any SIM in my test device so I've only tested on wifi. Can not comment on 3g/4g.

    I've confirmed this is an issue on both iOS 14.1 and 14.2.
     
  11. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Okay thanks, it seems is not the same bug then.
    Still if you could update us about what you find it would be great.
     
  12. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Just in case anyone is interested, we've solved this issue.

    The issue is that that port (10161) is reserved for SNMP over TLS and due to this was included in the list of criteria that will flag local network access.

    This has been confirmed by Apple and they've indicated that after investigating further they intend on removing this restriction in a later version of iOS (it's not yet in any seeded release).

    I gotta say, feeling rather unlucky to be allocated one of the very few ports of the 65535 we could have been allocated that caused this issue!
     
    pistoleta likes this.
  13. wesselb

    wesselb

    Joined:
    May 29, 2018
    Posts:
    6
    Hi! I'm also struggling with this error. Do you maybe have a full example of the code? I'm getting a lot of errors when I try to import this.
     
  14. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422

    You'll need to replace the <add remote ip address here> with an actual address.