Developer Dave Nottage has upgraded his network state library for Delphi XE8 Firemonkey. The latest version of the component includes an IOS64 version of the static libReachability.a library. If you are doing any kind of internet connections in Delphi XE8 this is a must have library. You should check if there is an internet connection on Android, IOS, OSX, and Windows prior to attempting to making a connection. The component is free. Even if you are only using the app tethering functionality of Delphi XE8 Firemonkey you should also use this component. There are multiple ways to check for an internet connection and this is one of them. In certain instances it is not enough however to just use the library (like for example when an IOS device has it’s internet connection disabled). A second important piece that I use is this function created by Daniel Magin (you can change out the google.com host for your own domain name):
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.
The code is good, but does not works in Android 6.x versions or above
Regards.
Why not? What is failing exactly? TIdTCPClient does not have any known issues on Android 6+ (only TIdSSLIOHandlerSocketOpenSSL does).
did not working in adroid phone just working in windows.