Unity/코드 예제들

모바일 네트워크 상태 확인

소나무꼴 2020. 10. 30. 21:39

Application.internetReachability == NetworkReachability.NotReachable // 인터넷 연결이 안되었을때.
Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork // 와이파이 연결
Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork // LTE 5G등 데이터 연걸

 

 

    private void CheckTransferNetwork()
    {
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            return;
        }
        NetworkReachability _now = Application.internetReachability;
        NetworkReachability _prev = network_state;
        if (_now != _prev)
        {
            //네트워크 상태 변화
            network_state = _now;
            if (_prev == NetworkReachability.NotReachable)
            {
                return;
            }
            if (_prev == NetworkReachability.ReachableViaLocalAreaNetwork)
            {
                Close();
                OnChangeNetwork?.Invoke();
            }
        }
    }