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);
}
}