With this function you can check and see 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, and this option is currently only for the Nintendo Switch target. 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 Switch OS to hang for a few seconds.
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.
os_is_network_connected([attempt_connection]);
| Argument | Type | Description |
|---|---|---|
| attempt_connection | Attempt Connection Constant | OPTIONAL For the Nintendo Switch target only. Set this parameter to a value other than network_connect_none / false to attempt an OS level connection when called. |
| Constant | Description |
|---|---|
| network_connect_none / false | This does not attempt to connect. |
| network_connect_blocking / true | This attempts to connect and blocks execution while trying. |
| network_connect_active / network_connect_nonblocking | This will actively prompt the user to fix the connection. |
| network_connect_passive | This will try to connect and silently fail if no succesful connection could be established. |
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.