os_is_network_connected

With this function you can check if your device currently has an internet connection.

It will return true if it does, or false if it does not. Depending on the value of the attempt_connection argument and the OS, it may attempt to make a connection before returning a value.

The function has an optional argument to enable/disable it attempting to make a connection when called. When set to anything other than network_connect_none the function will attempt to make a connection, and when set to network_connect_none it will simply be limited to checking the connection. Note that attempting to make a connection using network_connect_blocking may cause the OS to hang for a few seconds.

You can pass one of the following constants into the attempt_connection argument:

Attempt Connection Constant
ConstantDescription
network_connect_none / falseThis does not attempt to connect.
network_connect_blocking / trueThis attempts to connect and blocks execution while trying.
network_connect_active / network_connect_nonblockingThis will actively prompt the user to fix the connection, if it failed.
network_connect_passiveThis will try to connect and silently fail if no successful connection could be established.

If the function returns false when using network_connect_active or network_connect_passive, the actual result is returned later in the Async Networking event. See: Attempting Connection

NOTE This function checks the internal device API that controls connections and so may return true if there is a Bluetooth connection, a Wi-Fi connection, or even just a normal network connection that permits internet access. This means it may not always be accurate on all platforms.

Syntax:

os_is_network_connected([attempt_connection]);

ArgumentTypeDescription
attempt_connectionAttempt Connection ConstantOPTIONAL Set this parameter to a value other than network_connect_none to attempt an OS level connection when called.

 

Boolean

 

Example:

if os_is_network_connected()
{
    global.connected = true;
}

The above code checks to see if the device has a connection to the internet and if so it sets a global variable.