WinRT错误:未实现

时间:2015-05-15 17:49:11

标签: javascript windows-runtime windows-phone-8.1

我尝试使用 Windows.Networking.Connectivity.ConnectionProfile 类方法 getAttributedNetworkUsageAsync()方法来获取移动应用程序传输的字节数。但是当我在 windows phone OS 10 上调用getAttributedNetworkUsageAsync()时,它会抛出错误 WinRT错误:未实现。我是Windows手机开发的新手。所以,请帮帮我 这是我的代码

    var networkInfo = Windows.Networking.Connectivity.NetworkInformation;
    var connectivityNS = Windows.Networking.Connectivity;
    var currTime = new Date();
    var result;
    //Set start Time to 1 hour (3600000ms) before current time
    var startTime = new Date(currTime);
    startTime.setHours(startTime.getHours() - 1);

    //Get the ConnectionProfile that is currently used to connect to the Internet
    var connectionProfile = networkInfo.getInternetConnectionProfile();
    var networkUsageStates = {          
        roaming: connectivityNS.TriStates.doNotCare,
        shared: connectivityNS.TriStates.doNotCare
    };

    if (connectionProfile === null) {
            WinJS.log && WinJS.log("Not connected to Internet\n\r", "sample", "status");
    }
    else {
        connectionProfile.getAttributedNetworkUsageAsync(startTime, currTime, networkUsageStates)
            .then(successCallback,errorCallback);}

这是 successCallback 函数

function successCallback(networkUsage){    
        for (var i = 0; i < networkUsages.size; i++) {                                                      
        result =
        {
            bytesSent: networkUsages[i].bytesSent,
            PacketSent: 0, //not supported in windows
            BytesReceived: networkUsages[i].bytesReceived,
            PacketReceived: 0   //not supported in windows
        };
    }
}

这里是 errorCallback

function errorCallback(error) {
    WinJS.log && WinJS.log("An error has occurred: " + error, "sample", "error");
}

0 个答案:

没有答案
相关问题