Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodDelphiDemoFiremonkeyIOS

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.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

17 Comments

Leave a Reply