终于找到了为什么有些用户报告崩溃而其他用户说他们没有问题。我使用 NetworkService 类来检查互联网连接。但显然这不适用于 WP 8。有没有办法重做这个,所以它可以在两个操作系统上工作?我的 NetworkServices.cs 的这一行出现异常
返回 profile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
网络服务.cs:
{
public class NetworkService : INetworkService
{
public bool IsConnectionAvailable
{
get
{
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null)
{
return false;
}
return profile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
}
}
}
相关 MainPage.cs:
if (data.IsDownloaded)
{
this.PlaySound(IsolatedStorageFile.GetUserStoreForApplication().OpenFile(data.SavePath, FileMode.Open, FileAccess.Read, FileShare.Read));
}
else
{
if (!SimpleIoc.Default.GetInstance<INetworkService>().IsConnectionAvailable)
{
MessageBox.Show("You need an network or cellular connection to download.");
}
堆栈跟踪:
{System.NotImplementedException:方法或操作未实现。在 Windows.Networking.Connectivity.ConnectionProfile.GetNetworkConnectivityLevel() 在 App.Services.NetworkService.get_IsConnectionAvailable() 在 App.MainPage.LongListSelector_SelectionChanged(Object sender, SelectionChangedEventArgs e) 在 Microsoft.Phone.Controls.LongListSelector.set_SelectedItem(Object value) 在Microsoft.Phone.Controls.LongListSelector.OnItemTap(Object sender, GestureEventArgs e) 在 MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) 在 MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)} System.Exception {System.NotImplementedException}