Xamarin.Forms 引用冲突

Xamarin.Forms Reference conflict

我的问题在Xamarin.Forms

我尝试使用 Xamarin 中的 class Reachability.cs(从官方来源下载)使用检查 url 或 ip 地址是否可达。

当我尝试构建时显示以下错误消息:

Reference to type 'IPAddress' claims it is defined in 'System', but it could not be found

不知道怎么解决 我的用法是

using System;
using SystemConfiguration;
using CoreFoundation;

亲切的问候,

斯蒂芬

IP 地址是 System.Net 的一部分 添加

using System.Net;

关于您的使用 - 它没有列在您的问题中

检查您的参考中是否选择了以下程序集(右键单击参考,编辑参考,所有 - 我希望名称正确,因为我的 xamarin studio 是德语的)

  • 系统
  • System.Core
  • System.Xml
  • System.iOS

将 reachability.cs 添加到您的项目

将此行添加到 c'tor 或 class 您想要使用可达性内容的其他地方

UpdateStatus (null, null);
Reachability.ReachabilityChanged += UpdateStatus;

添加事件处理程序

void UpdateStatus (object sender, EventArgs e)
    {
        Console.WriteLine(Reachability.RemoteHostStatus ().ToString());
        Console.WriteLine(Reachability.InternetConnectionStatus ().ToString());
        Console.WriteLine(Reachability.LocalWifiConnectionStatus ().ToString());

    }

Reachability.cs 依赖 System.Net 类 而 PCL 中不存在。要在表单中测试可达性,请改用 Connectivity 插件。