Hi guys,

I'm working on a mobile app that works with geolocations and GPS. In order to have the best GPS functionality for iPhone I want to check if the user has WiFi enabled. 

Even if the WiFi setting in the iPhone is on, but not connected to a WiFi point, the GPS functionality starts to work better. Currently I'm using the GetNetworkType, which works fine for checking if the connection the user has is through WiFi or not. However this is not what I want to be checking.

With a little research on the forum and googling, I wasn't able to come up with an answer.

Anyone who has experience with this or who can help me?

Hi Perry,

As you mentioned the built in methods identify if there is a connection and I couldn't find anything under the navigator.connection to verify if the wifi is turned on or not.

However, a quick search on google shows there is something on the cordova-diagnostic-plugin that I think will solve your issue.

Under the WiFi module you can find some promising methods, especially the isWifiEnabled():


isWifiEnabled()

Platforms: Android, iOS and Windows 10 UWP

On iOS this returns true if the WiFi setting is set to enabled (regardless of whether it's connected to a network). On Android and Windows 10 UWP this returns true if the WiFi setting is set to enabled, and is the same as isWifiAvailable() On Android this requires permission <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

cordova.plugins.diagnostic.isWifiEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is true if the device setting is enabled.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isWifiEnabled(function(enabled){
    console.log("WiFi is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});


A quick search on the forge reveals the Diagnostic Plugin which implements the isWifiEnabled() method.

This forge component supports version 10 but you shouldn't have any issues upgrading it to version11.

Cheers