Unity判断手机网络是wifi或者4G

在开发网络模块的时候,往往会用到判断当前网络的代码,unity早已把它封装好,具体代码如下:

   void CheckNet()
    {
        switch (Application.internetReachability)
        {
            case NetworkReachability.NotReachable:
                Debug.Log("网络已断开");
                break;
            case NetworkReachability.ReachableViaLocalAreaNetwork:
                Debug.Log("wifi连接中");
                break;
            case NetworkReachability.ReachableViaCarrierDataNetwork:
                Debug.Log("4G/3G网络连接中");
                break;
        }
    }

猜你喜欢

转载自blog.csdn.net/leemu0822/article/details/81503090
今日推荐