Because the core modules in the project need to use network connectivity, it is necessary to first detect whether the user has a network
Baidu, some people say by connecting their own server to test, some people say through the delay to judge the
Finally, unity was found to provide a method of network judgment.
Networkreachability Network Accessibility
Enumeration
Describes network reachability options.
Describes the accessibility options for the network.
Values value
Notreachable
Network is not reachable.
Reachableviacarrierdatanetwork
Network is reachable via carrier data network
The network is accessible through the operator data network.
Reachablevialocalareanetwork
Network is reachable via WiFi or cable
The network is accessible via WiFi or a wired network.
Can be judged directly in the project by the following code
[Code]csharpcode:
When the network is unavailable
if (application.internetreachability== networkreachability.notreachable)
{
Do sth.
}
If the project requires a large amount of traffic, it can be judged by the following method and prompt the user
[Code]csharpcode:
When the user is using WiFi
if (application.internetreachability = = networkreachability.reachablevialocalareanetwork)
{
Do sth.
}//When the user is using the mobile network
if (application.internetreachability = = networkreachability.reachableviacarrierdatanetwork)
{
Do sth.
}
Unity determines whether the network is connected and determines whether WiFi is connected