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

Check Network State Delphi FiremonkeyIf 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
AndroidComponentDelphiDemoFiremonkeyIOSLinuxOSXShowcaseWindows

Experience ChatGPT As A Native Cross-Platform Firemonkey Application

DelphiLibraryWindows

Run Large Language Models Entirely On The GPU With Delphi And Vulkan

Code SnippetDelphiDemoLibraryWindows

Add Real-Time AI Voice Conversations To Windows Applications

ComponentDelphiDemoLibraryWindows

Give AI Models Eyes, Ears, And Real-World Capabilities

Sign up for our Newsletter and
stay informed
[mailpoet_form id="1"]

17 Comments

Leave a Reply