Unity判断网络连接类型

使用NetworkReachability判断手机游戏当前的网络连接类型,是wifi还是234G

 using UnityEngine;
using System.Collections; public class Test : MonoBehaviour { string str;
// Use this for initialization
void Start () {
if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
{
str = "2G/3G/4G";
}
else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
str = "wifi";
}
else if (Application.internetReachability == NetworkReachability.NotReachable)
{
str = "No Network";
} } // Update is called once per frame
void Update () { } void OnGUI()
{
GUILayout.Label(str);
}
}
上一篇:iOS编程(双语版)-视图-Autolayout代码初步


下一篇:HttpUtil 【判断网络连接的封装类】