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; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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.

Head over and download the network state component library for checking the internet connection in Delphi XE8 Firemonkey.