问题描述
限时送ChatGPT账号..我需要在我的 WP8.1 应用程序代码中检查操作系统版本(WP 8.1 或 W10).有什么更好的方法来做到这一点?为此目的可能是反射或一些特殊的API?
I need to check OS version (WP 8.1 or W10) in my code of WP8.1 application. What better way to do this? May be reflection or some special API for this purpose?
推荐答案
我没有找到任何其他方法可以做到这一点,所以这是我的方法.
I didn't find any other way to do this, so here's my approach.
以下属性 IsWindows10
可检测 Windows 8.1 或 Windows Phone 8.1 应用是否在 Windows 10(包括 Windows 10 移动版)设备上运行.
The following property IsWindows10
detects if a Windows 8.1 or Windows Phone 8.1 app is running on a Windows 10 (including Windows 10 Mobile) device.
#region IsWindows10
static bool? _isWindows10;
public static bool IsWindows10 => (_isWindows10 ?? (_isWindows10 = getIsWindows10Sync())).Value;
static bool getIsWindows10Sync()
{
bool hasWindows81Property = typeof(Windows.ApplicationModel.Package).GetRuntimeProperty("DisplayName") != null;
bool hasWindowsPhone81Property = typeof(Windows.Graphics.Display.DisplayInformation).GetRuntimeProperty("RawPixelsPerViewPixel") != null;
bool isWindows10 = hasWindows81Property && hasWindowsPhone81Property;
return isWindows10;
}
#endregion
它是如何工作的?
在 Windows 8.1 中,Package
类具有 Windows Phone 8.1 没有的 DisplayName
属性.在 Windows Phone 8.1 中,DisplayInformation
类具有 Windows 8.1 没有的 RawPixelsPerViewPixel
属性.Windows 10(包括移动版)具有这两个属性.这就是我们如何检测应用在哪个操作系统上运行的方法.
In Windows 8.1 the Package
class has a DisplayName
property, which Windows Phone 8.1 doesn't have.
In Windows Phone 8.1 the DisplayInformation
class has a RawPixelsPerViewPixel
property, which Windows 8.1 doesn't have.
Windows 10 (including Mobile) has both properties. That's how we can detect which OS the app is running on.
这篇关于如何检测在 Windows 10 Mobile 上启动的 WP8.1 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论