我是Angular2的初学者。我正在尝试在Angular2中编写一个应用程序。现在我可以使用navigator.userAgent来检测浏览器名称。
如果用户在Windows上使用Chrome。数据类似于{'浏览器':' Chrome'}
如果用户在iphone上使用Safari,则数据类似于{'浏览器':' Safari'}
如果用户在Android上使用Firefox,则数据类似于{'浏览器':' Firefox'}
public static DeviceDetector():string {
let ua:string = navigator.userAgent;
let browser:string;
if (ua.indexOf("Chrome") > -1) {
browser = "Google Chrome";
} else if (ua.indexOf("Safari") > -1) {
browser = "Apple Safari";
} else if (ua.indexOf("Opera") > -1) {
browser = "Opera";
} else if (ua.indexOf("Firefox") > -1) {
browser = "Mozilla Firefox";
} else if (ua.indexOf("MSIE") > -1) {
browser = "Microsoft Internet Explorer";
}
return browser;
}
想知道如何在Angular2中获取当前设备UUID?因为我试图调用的API需要设备ID和名称。我检查了现有Windows Mobile客户端的代码,发现了一个名为 Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()
的函数public static string GetDeviceName(out string strDeviceID, out string strDeviceName)
{
strDeviceID = "";
strDeviceName = "";
var deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
if (deviceInfo == null)
return "We are unable to sign you into server as you device name cannot be determined. Please try rebooting your device and trying again.";
strDeviceID = deviceInfo.Id.ToString();
strDeviceName = deviceInfo.FriendlyName;
return "";
}
我需要在Angular2中编写类似windows mobile客户端的东西。是否可以获得这样的设备ID?