Xamarin.iOS app asking Local Network permission in iOS 14.0

2.3k views Asked by At

I have Xamarin.iOS app in production which is asking Local Network permission on launch on iOS 14 devices. App is not using any Bonjour service nor using anything specific to local network. App has various nuget packages including Xamarin.Essentials, MvvmCross, Firebase services, Realm DB, etc.

I have gone through various open threads on developer.apple.com including WWDC2020 video but still did not get what is triggering this Permission dialog.

2

There are 2 answers

1
Gopal On BEST ANSWER

After lots of trials and errors we are finally able to identify the local network permission trigger point.

  • This prompt is triggering due to SSHConnection check method we using to identify jailbroken iPhone devices.
  • This method checks whether an SSH Clients try to make connection to 127.0.0.1(localhost) on port 22 If the connection succeeds, the device is jail broken.
  • This code causing permission prompt CrossConnectivity.Current.IsRemoteReachable("127.0.0.1", 22, 5000);
0
George M Ceaser Jr On

So my App uses socket communications and the first time the app creates a connection, the user is being prompted with this permissions prompt. Unfortunately this is causing my first attempt at a socket communication to fail. To get around this, I add the following code in the very beginning of my app life cycle. (I have a configuration page that always displays the first time the app is launched so I added it there.) This code then forces the permissions prompts. One thing I noted is, if I didn't use the same ipaddress / port when forcing the prompt as I will use later to make my socket connection, I was prompted for the permissions a SECOND time. ( I was using IP Address 192.0.0.1 and port 20.) That was rather frustrating. I could also not seem to find a way to check for this permission

Regardless here is some simple code that can force the prompt earlier in you app to prevent communication challenges when you actually try to connect.

    public async static void ForcePermissions(string ps_IPAddress, int pi_Port)
    {
        try
        {

            IPAddress ipAddress = IPAddress.Parse(ps_IPAddress);
            //This is only done to force the local network permissions access in iOS 14. 
            IPEndPoint remoteEndPoint = new IPEndPoint(ipAddress, pi_Port);

            // Create a TCP/IP socket.  
            var client = new Socket(ipAddress.AddressFamily,
                                SocketType.Stream, ProtocolType.Tcp);

            var lb_ReturnValue = await client.ConnectAsync(remoteEndPoint).ConfigureAwait(false);

        }
        catch (Exception ex)
        {
            App.ProcessException(ex);
        }
    }