Unity determines whether the network is connected and determines whether WiFi is connected

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.