Hi,
I am looking for a system which determine if internet is available when i launch my app.
After searching on internet i have try many solution and on editor this one works :
IEnumerator CheckConnectionToMasterServer() {
Ping pingMasterServer = new Ping("74.125.224.72");
float startTime = Time.time;
while (!pingMasterServer.isDone && Time.time < startTime + 5.0f) {
yield return new WaitForSeconds(5.0f);
}
if(pingMasterServer.isDone && pingMasterServer.time > 2) {
Debug.Log ("IntenetON" );
} if(pingMasterServer.isDone && pingMasterServer.time<=1) {
Debug.Log ("IntenetOFF" );
}
}
When i build an apk for android there is no problem, ping works (cause i am connected to wifi).
If i launch with no internet connection my app instantly crash
I have try to comment the while and always wait 5 seconds to check the ping result and its still crashing...
Anyone can solve this issue ?
Thank you.
↧