public IEnumerator CheckInternetConnection(List <string> _urls, Action <bool> _successAct = null) { if (myInternetConnection == InternetConnectionCapability.Testing) { yield break; } myInternetConnection = InternetConnectionCapability.Testing; foreach (string ur in _urls) { if (myInternetConnection == InternetConnectionCapability.Okay) { yield break; } yield return(StartCoroutine(CheckInternetConnection(ur, _successAct))); } }
public IEnumerator CheckInternetConnection(string _url, Action <bool> _successAct = null) { using (var uwr = UnityWebRequest.Get(_url)) { uwr.timeout = 30; // InternetConnection check MUST be done in 30 seconds yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { myInternetConnection = InternetConnectionCapability.ConnectionBlocked; if (_successAct != null) { _successAct(false); } yield break; } myInternetConnection = InternetConnectionCapability.Okay; if (_successAct != null) { _successAct(true); } } }