Windows 10 get DeviceFamilyVersion

后端 未结 4 1681
清酒与你
清酒与你 2020-12-06 07:51

I\'m working windows 10 10240 Univasal windows app, when i use Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion to get deivce version, it return a string

4条回答
  •  一生所求
    2020-12-06 08:17

    If you found this question and like me you are looking for a way to do this in JavaScript, then you might find this useful.

    getDeviceFamilyVersion() {
        let deviceFamilyVersion = Windows.System.Profile.AnalyticsInfo.versionInfo.deviceFamilyVersion;
        let deviceFamilyVersionDecimalFormat = parseInt(deviceFamilyVersion);
    
        if (isNaN(deviceFamilyVersionDecimalFormat)) {
            throw new Error('cannot parse device family version number');
        }
    
        let hexString = deviceFamilyVersionDecimalFormat.toString(16).toUpperCase();
    
        while (hexString.length !== 16) { // this is needed because JavaScript trims the leading zeros when converting to hex string
            hexString = '0' + hexString;
        }
    
        let hexStringIterator = 0;
        let versionString = '';
        while (hexStringIterator < hexString.length) {
            let subHexString = hexString.substring(hexStringIterator, hexStringIterator + 4);
            let decimalValue = parseInt(subHexString, 16);
    
            versionString += decimalValue + '.';
            hexStringIterator += 4;
        }
    
        return versionString.substring(0, versionString.length - 1);
    }
    

提交回复
热议问题