os_is_network_connected

使用此函数,您可以检查您的设备当前是否有互联网连接。

如果是,它将返回TRUE,如果不是,它将返回FALSE。根据attempt_connection参数的值和OS ,它可能会尝试在返回值之前进行连接。

该函数有一个可选参数,用于启用 / 禁用它在调用时尝试建立连接。当设置为network_connect_none 以外的任何值时,该函数将尝试建立连接当设置为 network_connect_none时,它将仅限于检查连接。请注意,尝试使用 network_connect_blocking建立连接可能会导致操作系统挂起几秒钟。

您可以将以下常量之一传递给 attempt_connection 参数:

尝试连接常量
常量描述
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

注意 此函数检查控制连接的内部设备 API,因此如果存在蓝牙连接、Wi-Fi 连接,甚至只是允许互联网访问的正常网络连接,则可能返回 true。这意味着它在所有平台上可能并不总是准确的。

语法:

os_is_network_connected([attempt_connection]);

参数类型描述
attempt_connection尝试连接常量可选 将此参数设置为 network_connect_none 以外的值,以在调用时尝试操作系统级别的连接。

 

Boolean

 

例子:

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

上面的代码检查设备是否连接到互联网,如果连接到互联网,它会设置一个全局变量。