我有一個我爲Windows創建的應用程序:PC /平板電腦8.1,移動/電話8.1和UWP 10.如何確定Windows應用程序的操作系統(OS)(UWP/PC/Tablet 8.1/Mobile 8.x)?
這是一個使用C#的WinRT應用程序。
要在應用中放置廣告條幅,需要爲每個操作系統製作一個單獨的廣告單元ID。
是否有方法可以確定當前正在使用哪個操作系統?
它可以檢查正在使用的設備利用代碼:
#if WINDOWS_PHONE_APP
isWindowsPhoneApp = true;
#else
isWindowsPhoneApp = false;
#endif
但如何知道,如果操作系統是Windows 8.1或Windows 10?
UPDATE:
我曾經碰到過一個有趣的文章有關獲取操作系統版本爲C#/ XAML:
Windows Store Apps: Get OS Version, beginners tutorials (C#-XAML)
它使用System.Type.GetType檢查Windows.System。 Profile.AnalyticsVersionInfo返回null。
我修改並測試了代碼,它似乎可以在Visual Studio模擬器和模擬器中工作。我無法測試Windows 8.1計算機,因爲我使用的是Windows 10計算機,但對於Windows Phone 8.1和Windows 10 Mobile而言,這是準確的。我沒有在實際的電話設備上測試過它。
因此,檢查僅在Windows 10中可用的AnalyticsVersionInfo的類型似乎會根據操作系統返回true或false。
那麼下面的代碼應該推薦在發佈版本中使用嗎?
var analyticsVersionInfoType = Type.GetType("Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime");
var isWindows10 = analyticsVersionInfoType != null;
displayTextBlock.Text = "Is Windows 10: " + isWindows10;
UPDATE:
一行代碼:
var isWindows10 = Type.GetType("Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime") != null;
此.NET代碼在我的WinRT應用程序中不起作用。另外,頁面上的第一個標註爲「重要」的註釋表示:「我們不建議您檢索此屬性的值來確定操作系統版本」,這正是我想要做的。 – theMaxx