简体   繁体   English

Xamarin iOS可达性不起作用

[英]Xamarin ios reachability not working

First I am new to Xamrain Mobile application Developer. 首先,我是Xamrain移动应用程序开发人员的新手。

I added class reachability.cs inside ios mobile applictaion. 我在ios移动应用程序内添加了类reachability.cs。 Now I want to check before or in between a service call, whether Internet is connect or not. 现在,我想检查服务呼叫之前或之间,是否连接了Internet。 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. 这是在Xamarin for iOS中实现可达性的正确方法吗?

Please advice me if I am doing any thing wrong. 如果我做错任何事情,请告诉我。

@All Thanks in advance @All提前谢谢

The InternetConnectionStatus does not return a boolean but a status, so you should compare Reachability status: InternetConnectionStatus不返回布尔值而是一个状态,因此您应该比较可达性状态:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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