function TdmMain.CheckInternet: boolean;
begin
result:=false;
try
IdTCPClient1.ReadTimeout:=2000;
IdTCPClient1.ConnectTimeout:=2000;
IdTCPClient1.Port:=80;
IdTCPClient1.Host:='google.com';
IdTCPClient1.Connect;
IdTCPClient1.Disconnect;
result:=true;
except
result:=false;
end;
end;
Be aware however that on IOS you must make internet connections asynchronously otherwise you risk the chance that IOS will close your application. If your connection takes more than ~10 seconds IOS may think your app is frozen and close it. What I do is set up a private boolean variable which contains the internet status. I then update this variable using the various methods and when I need to know the internet state I just check the boolean variable. This library and code should also work in Appmethod. You can check out our previous post about the network state component here.
Must Have Check Network Connectivity State Library For #Delphi XE8 Firemonkey On #Android And #IOS
