Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Check Network Connectivity State With Delphi XE5 Firemonkey On Android And IOS

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Check Network State Delphi Firemonkey | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSIf you are looking for a cross platform way to check for connectivity in your Delphi Firemonkey apps on Android and IOS then this might be the solution for you. It is a simple set of free classes that lets you do just that. For IOS it requires a small static library be included as well. It has properties to report back on if there is any connectivity at all and whether that connectivity is via Wifi or Mobile data. Personally I found it pretty useful because it is cross platform and will tell you the connectivity regardless if it is Android or IOS. It doesn’t report connectivity on Windows so you’ll have to add that part yourself with IFDEFs.

TCustomNetworkState = class(TObject)
  function GetSSID: String; virtual; abstract;
  function IsConnected: Boolean; virtual; abstract;
  function IsWifiConnected: Boolean; virtual; abstract;
  function IsMobileConnected: Boolean; virtual; abstract;
end;


You can also use some code like this from Daniel Magin as a backup if you need to (put your own domain place of google.com):
function 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;

Update: Apparently on IOS you should never do synchronous network calls (including this check connectivity functionality) in the main thread. We’ve run into problems with this on iPad Air devices. One recommendation is to place this connectivity check in an anonymous background thread.

Head over and download the class and demo for NetworkState.

Exit mobile version