简体   繁体   English

Windows 10移动UWP应用比wifi更喜欢蜂窝数据。 如何处理多个网络连接

[英]Windows 10 Mobile UWP app prefers cellular data over wifi. How to handle multiple network connections

I have Windows 10 Mobile application. 我有Windows 10移动版应用程序。 I noticed the other day that some of my server communication and network access calls/code were all failing. 前几天,我注意到我的某些服务器通信和网络访问呼叫/代码都失败了。 The mobile device I was using had Cellular data and Wifi options both turned on in the settings. 我使用的移动设备的“蜂窝数据”和“ Wifi”选项均在设置中打开。 I was connected to my Wifi just fine. 我已经连接到我的Wifi上网了。 However, the cellular data was not activated on this device. 但是,蜂窝数据未在此设备上激活。 It shows cellular is turned on and shows some bars but the service is not activated with the carrier. 它显示蜂窝电话已打开,并显示一些条,但该服务未通过载体激活。

During troubleshooting, I turned off the cellular data option in settings and once I did that, all of my server and network access code started working again (ie. not throwing exceptions). 在故障排除过程中,我关闭了设置中的“蜂窝数据”选项,一旦这样做,我所有的服务器和网络访问代码便重新开始工作(即,不引发异常)。

I have been searching for a while and have not been able to find the answer to my assumption that Windows 10 Mobile, when both cellular data and wifi are turned on will default to using cellular first, even if cellular is not working. 我已经搜索了一段时间,但无法找到我的假设的答案,即当蜂窝数据和wifi都打开时,Windows 10移动将默认先使用蜂窝,即使蜂窝无法正常工作也是如此。 Is this true? 这是真的? Maybe a better way to ask the question is, how does the device handle when you have two data connection sources enabled? 可能提出一个更好的方法是,当您启用两个数据连接源时,设备如何处理? How does it choose which one to use? 如何选择使用哪一个?

Maybe the follow up question also is, how do I force it to use one or the other? 也许后续问题也是,我如何强迫它使用一个或另一个? I have seen during me research, alot of code on how to detect which network connection is active but not much information on what happens if more than one are active and how to force the OS to use one or the other. 在研究过程中,我看到了很多代码,这些代码如何检测到哪个网络连接处于活动状态,但是如果有多个连接处于活动状态,以及如何强制操作系统使用其中一个或另一个,则没有太多信息。 This could come in handy if I want to seamlessly switch my calls from wifi to cellular. 如果我想将通话从wifi无缝切换到蜂窝,这可能会派上用场。 For example, prefer wifi and use wifi but if you go out of range of wifi, then switch to cellular. 例如,更喜欢使用wifi并使用wifi,但是如果您超出了wifi的范围,请切换到蜂窝网络。

Thanks! 谢谢!

When we connect the Wifi, the UWP app will use the WIFI no matter the Cellular data is turn on. 当我们连接Wifi时,无论蜂窝数据是否打开,UWP应用都将使用WIFI。

You can use the following code to check your UWP app use cellular data or Wifi, you can also check the signal level of the current network. 您可以使用以下代码检查您的UWP应用使用的蜂窝数据还是Wifi,还可以检查当前网络的信号电平。

ConnectionProfile profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
if (profile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
{
    Debug.WriteLine("InternetAccess");
}
var signal = profile.GetSignalBars();
Debug.WriteLine("signal is:"+signal);
if (profile.IsWlanConnectionProfile)
{
    Debug.WriteLine("Wifi");
}
else if (profile.IsWwanConnectionProfile)
{
    Debug.WriteLine("Cellular");
}

When Cellular data and Wifi options both turned on in the settings and they are connected, ConnectionProfile.IsWwanConnectionProfile will return true. 当蜂窝数据和Wifi选项都在设置中打开并连接时, ConnectionProfile.IsWwanConnectionProfile将返回true。

When the Wifi is disconnected, it will use the Cellular data automatic. Wifi断开连接时,它将自动使用蜂窝数据。 We can not force UWP app use cellular data or Wifi by code. 我们不能通过代码强制UWP应用使用蜂窝数据或Wifi。 We can add the NetworkInformation.NetworkStatusChanged , it occurs when the network status changes for a connection. 我们可以添加NetworkInformation.NetworkStatusChanged ,它会在连接的网络状态更改时发生。 When the Wifi is disconnected, the event will be fired and ConnectionProfile.IsWwanConnectionProfile will return true. 当Wifi断开连接时,将触发该事件,并且ConnectionProfile.IsWwanConnectionProfile将返回true。

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

相关问题 Windows 10 UWP - 检测当前的Internet连接是Wifi还是Cellular? - Windows 10 UWP - detect if the current internet connection is Wifi or Cellular? 如何在Windows 10移动应用中使用LumiaImagingSDK.UWP 3.0? - How to work with LumiaImagingSDK.UWP 3.0 in windows 10 mobile app? 使用 uwp 应用程序在两个 windows 设备之间通过 wifi 共享文件 - Sharing files over wifi between two windows devices with a uwp app 如何确定我是否在Windows Phone 8.1(通用应用程序)中连接到WiFi或移动网络? - How can I determine whether I am connected to WiFi or a mobile network in Windows Phone 8.1 (Universal app)? 关于 Windows Mobile 上的网络连接 - About Network Connections on Windows Mobile FolderPicker在UWP Windows 10应用程序(移动)中不起作用 - FolderPicker does not work in UWP Windows 10 app (mobile) 在状态栏中更改图标的颜色-Windows 10移动UWP应用 - Change color of icons in status bar - Windows 10 Mobile UWP app 在Windows 10移动版中启动UWP应用期间出错 - Error during UWP app launch in Windows 10 mobile Windows 10 UWP应用:通过移动宽带的StreamSocket - Windows 10 UWP app: StreamSocket via mobile broadband 如何处理WebView中的确认对话框? UWP Windows 10应用程序C# - How can i handle confirm dialog in webview? UWP windows 10 app C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM