- Home /
 
               Question by 
               gmort346 · Dec 08, 2014 at 04:19 PM · 
                androidandroid iphone  
              
 
              Application.internetReachability does not update (on android)
I have an app that requires local network connection (wifi)
I do not need to have internet connection, but must have local access...
I found Application.internetReachability and it has ReachableViaLocalAreaNetwork which seems to do what I need, however it only seems to work at start up
if I start the app without wifi enabled - it tells me no wifi... if I start the app with wifi enabled - it tells me wifi....
but if I change the wifi state mid game, the state does not update?
is there a way to force refresh the internetReachability?
I need this to work on iOS and Android, I have only tested this on Android so far
               Comment
              
 
               
              Answer by VamshiKrishnaP · Dec 19, 2014 at 11:44 AM
you can check the internet connection like this :
  using UnityEngine;
  using System.Collections;
  using System;
  
  public class NetConnection : MonoBehaviour {
  
      bool IsInternet=false;
  
      
      void Start(){
          InvokeRepeating("hai",0,1);
      }
  
      void hai(){
          StartCoroutine(checkInternetConnection((isConnected)=>{
              IsInternet=isConnected;
          }));
      }
  
      IEnumerator checkInternetConnection(Action<bool> action){
          WWW www = new WWW("http://google.com");
          yield return www;
          if (www.error != null) {
              action (false);
          } else {
              action (true);
          }
      } 
  
      void OnGUI(){
          GUI.Label(new Rect(0,400,150,100),""+IsInternet);
      }
  
  }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                