Jump to content
Sign in to follow this  
Vince Bartlett

iOS Local Network Permission

Recommended Posts

Sorry if this has been asked before but I've not been able to spot anything appropriate.
 

My app needs to connect to the user's local network.

 

With iOS 14 (I believe) the OS started throwing up a confirmation of allowing the app to access it. Fair enough.

 

However if they choose to deny access, the app doesn't appear to get an an error or exception. The app has to be force terminated the restarted.

 

Once restarted, the warning isn't displayed again but the network call just fail. Neither can I find a way to enable the query so the permission can be enabled.

 

Anyone know of an example or description on how to handle this situation more elegantly?

 

Thanks for any assistance.

 

Share this post


Link to post

Yep, dead easy

 

Create a new multi device app.

 

Add a TIdUDPClient, a text and a button to the form. Add the following to the button click handler....

 

procedure TForm1.Button1Click(Sender: TObject);
begin
   try
      IdUDPClient1.Host := 'local_pc_name.local';
      IdUDPClient1.BoundPort := 8080;
      IdUDPClient1.Connect;

   except      
      on e: Exception do
      begin
         Text1.Text := e.Message;
      end;
   end;
end;

 

The first time that the above code is run, the confirmation box is displayed by iOS. If Allow is clicked, the call will execute as normal. If Don't Allow is selected, it all kind of hangs. If the app is terminated and rerun, then a more sensible error about can't resolve the address is received.

 

In the real app I'm actually using an Indy HTTP client component but the way this happens is identical as far as I can determine.

 

I'm using 10.4.2 if that makes any difference.

 

Cheers

Share this post


Link to post

Thanks for the reply but which protocol isn't the issue.

 

The issue is that iOS wants the app user to confirm that they will allow the app to access local network resources.

(I believe this was introduced to stop the more aggressive companies trying to create a unique user ID based on what they can sniff out on the local network for ad targeting I suppose)

 

If the user agrees, there isn't any issue - it all works as expected.

 

If the user chooses to deny access, there isn't an exception or error generated. The app effectively hangs and has to be force terminated.

 

Subsequent runs of the app doesn't display the same confirmation box and all network fails as if there's no active network connection. I can't find a way to perform any check if this has happened or a way to reset the test. It's pretty crappy user experience.

 

I guess this is pretty much as Apple intended. It's a pain there's no error reported. It's possible to change the text of the confirmation box which might be about the best I can do.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×