- Home /
Question by
gabrielesimula · Aug 07, 2020 at 04:46 PM ·
iosnetworkconnection
Network check does not work on iOS
Hello,
I am using the below code to check every 5min if there is an internet connection. Which is working very fine on Android, but it does not work on iOS (testFlight), can somebody advice whats wrong? thanks.
public void SetConnectionValiability() => StartCoroutine(CheckConnection((isConnected) => { IsOnline = isConnected; }));
IEnumerator CheckConnection(Action<bool> action)
{
const string echoServer = "http://google.com";
bool result;
using (var request = UnityWebRequest.Head(echoServer))
{
request.timeout = 5;
yield return request.SendWebRequest();
result = !request.isNetworkError && !request.isHttpError && request.responseCode == 200;
}
action(result);
}
Also for a commercial game, is it "legal" to ping google like that?
thanks in advance
Comment
Best Answer
Answer by gabrielesimula · Aug 10, 2020 at 10:54 AM
Solved, for anybody here, use https instead of http.
Your answer
Follow this Question
Related Questions
[iOS] Connect to WiFi network in the app 0 Answers
Alternate Connection Options 2 Answers
Client connects to server, but Network.peerType returns Disconnected until next click 2 Answers
IOS Networking 0 Answers