【问题标题】:Windows Phone 8.1 emulator check Internet connectionWindows Phone 8.1 模拟器检查 Internet 连接
【发布时间】:2016-02-29 20:46:52
【问题描述】:

我需要在模拟器中测试我的应用,检查互联网连接。 我正在使用以下课程(来自这里http://www.jayway.com/2015/04/23/how-to-verify-internet-access-in-universal-apps/):

public class Connection
{
    public static bool HasInternetAccess { get; private set; }

    public Connection() {
        NetworkInformation.NetworkStatusChanged += NetworkInformationOnNetworkStatusChanged;
        CheckInternetAccess();
    }

    private void NetworkInformationOnNetworkStatusChanged(object sender) {
        CheckInternetAccess();
    }

    private void CheckInternetAccess() {
        var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
        HasInternetAccess = (connectionProfile != null &&
                             connectionProfile.GetNetworkConnectivityLevel() ==
                             NetworkConnectivityLevel.InternetAccess);
    }
}

并使用类检查连接:

Connection conn = new Connection();
if (Connection.HasInternetAccess) {
      // some code
} else {
      MessageDialog msgbox = new MessageDialog("no internet");
      await msgbox.ShowAsync();
}

问题是我每次都在模拟器中变得真实。 我从这里How to disconnect Windows Phone 8.1 emulator from network? 尝试了解决方案,甚至重新启动了 PC,但没有任何改变。

在设备上的测试是正确的。如果连接启用则为真,如果连接禁用则为假。

附:对不起我糟糕的英语。

【问题讨论】:

    标签: c# windows-phone-8.1 emulation


    【解决方案1】:

    模拟器始终将 NetworkInformation.GetInternetConnectionProfile() 返回为 true,即使您将网络条件模拟为没有网络。

    使用物理设备测试应用程序。(它可以正常工作)。

    【讨论】:

      猜你喜欢
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      相关资源
      最近更新 更多