flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
9.59k stars 372 forks source link

Testing Flet app on iOS : dialog asking for permissions #1612

Closed Michel7GitHub closed 6 months ago

Michel7GitHub commented 10 months ago

I am new with Flet. I installed the new IOS Flet application on my iPad (V16.5.1) and my cell phone (V16.5.1c). I am developing my Flet apps on Windows 10. I have followed the "Testing Flet app on iOS" procedure and I have a problem at the step after reading the QR code. Nothing is running. My IPad, nor my IPhone does not display the Popup "dialog asking for permissions to access your local network". However, I have another application on my iPad which communicates very well with my computer. I tried to find a setting on my IPhone/IPad to grant access but couldn't find anything. Do you have an idea that could help me?

FeodorFitsner commented 10 months ago

My guess is that app URL built by Python Flet app is not accessible from your phone and iPad. While Flet does its best to determine computer external IP the algorithm could be non-ideal.

Take the app URL it shows in console above QR code and try opening it in the browser on your phone/iPad?

Michel7GitHub commented 10 months ago

Safari Browser can’t open the URL. Could it be an issue with my VPN?

FeodorFitsner commented 10 months ago

Make sure both computer and phone are connected to the same wi-fi network.

Michel7GitHub commented 10 months ago

It is

FeodorFitsner commented 10 months ago

What OS is on your computer?

Michel7GitHub commented 10 months ago

Windows 10

FeodorFitsner commented 10 months ago

By default, for iOS apps Flet server is listening on port 8551. Make sure this port is enabled/allowed in Advanced Windows Firewall.

Michel7GitHub commented 10 months ago

Original URL generated by the command FLET run —ios is http://10.x.y.z:49930/My-app/main-py I created an entry for port 8551 into Advanced Windows Firewall but it does’t change anything Then, I created and other entry with port 49930 and used the following URL http://192.168.0.163:49930/My-app/main-py and it works 49930 is the random generated port each time I execute FLET run —ios 192.168.0.163 s my wi-fi address 10.x.y.z is my VPN address

Michel7GitHub commented 10 months ago

Here are the conclusions of my latest research: In any case, a port number is automatically generated each time I start "flet run --ios" on my computer (Windows 10) and causes the following problem: In the FLET application of my Ipad, a new project is created each time a new port number is generated. For the same project on my computer, there are as many projects with the same name on my Ipad, each having a different port number. I then absolutely have to use the camera + QR code to start the application on my Ipad.

My VPN is causing some issues: When my VPN is disabled on my computer (Windows 10), there is no problem except for the randomly generated port. "flet run --ios" then generates a URL with a private IP 192.168.0.x When my VPN is activated on my computer (Windows 10), I have to create a private network. I use NordVPN and MESH to do this. Then, there is no problem except for the randomly generated port.

You said that FLET uses a dedicated port 8551. Should the port randomly generated by the "flet run --ios" command then be 8551?

FeodorFitsner commented 10 months ago

Thanks for your efforts to further investigate this issue.

Yes, when running with --ios flag the port should default to 8551 if not specified. It must be a bug if it doesn't work on Windows - will take a look.

Re: IP detection - currently Flet uses the following code to determine IP:

import socket
hostname = socket.gethostname()
ip_addr = socket.gethostbyname(hostname)

wondering what it gives to you when VPN is on/off? Any ideas how to improve that with VPN enabled?

FeodorFitsner commented 10 months ago

@Michel7GitHub Could you try using netifaces library on your machine to see what it returns? There is an instruction in the readme. I believe it could be installed into virtual env with pip install netifaces.

Michel7GitHub commented 10 months ago

Using flet run -p 8551 --ios, I solved all my problems. No need to modify Windows Defender anymore. VPN is not really an issue after I defined my VPN Private Network. Your notice was clear about that : Your iOS device and computer must be connected to the same Wi-Fi or local network I installed netifaces without problem on virtual .venv machine.

Michel7GitHub commented 10 months ago

One last thing about your installation guide. The procedure mentions

python3 -m venv .venv
source .venv/bin/activate
  1. source is not recognized as a command
  2. The bin directory does not exist. The activate script is located in the .venv/Scripts directory.
FeodorFitsner commented 10 months ago

yep, those instructions were for macOS/Linux. I will add Windows instructions as well. random port on Windows is a bug - will fix it shortly.

Michel7GitHub commented 10 months ago

Thank you for your time and devotion to this fantastic project. Have a nice continuity