简体   繁体   中英

Xamarin ios reachability not working

First I am new to Xamrain Mobile application Developer.

I added class reachability.cs inside ios mobile applictaion. Now I want to check before or in between a service call, whether Internet is connect or not. If mobile is not connected to internet it shows alertmessage "Please check the internet connection" if mobile is connect to internet it process the service request.

How to check if connected to network or not?

  Reachability reachabilityObj = Reachability.InternetConnectionStatus ();
        if (reachabilityObj == false) {

            Console.WriteLine ("Not connect to Internet");
        } else {
            Console.WriteLine ("connect to Internet");

        }

Is this is correct way of implementing Reachability in xamarin for ios.

Please advice me if I am doing any thing wrong.

@All Thanks in advance

The InternetConnectionStatus does not return a boolean but a status, so you should compare Reachability status:

Reachability reachabilityObj = Reachability.InternetConnectionStatus ();
if (reachabilityObj == NetworkStatus.NotReachable) {
    Console.WriteLine ("Not connect to Internet");
} else {
    Console.WriteLine ("connect to Internet");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM