network.setStatusListener()

Overview

Starts monitoring a host for its network reachability status. This API is designed around the idea that you are monitoring individual hosts and not the hardware directly. Potentially, some hosts might continue to be reachable while others are not due to internet conditions, firewall configurations, authentication rules, and whether you need full DNS routing.

Gotchas

Network reachability (networkStatus) events are only supported on macOS and iOS.

Currently only named hosts are supported. IP addresses will not work.

This API allows monitoring of multiple host URLs with separate or common event listeners. Call this API for each host URL to monitor.

There is a potential bug that returns a false connection status if you attempt to monitor a URL address with subfolders like "www.apple/xyz" on a cellular network. However, the URL should return the correct connection status when using WiFi.

Syntax

network.setStatusListener( hostURL, listener )

hostURL (required)

String. The host you want to monitor. This may be something like "www.coronalabs.com". You should not include http:// or the port number.

listener (required)

Listener. The listener that gets networkStatus events for the specified host. Pass nil to unregister the listener that's set for the specified host.