第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iPhone數(shù)據(jù)使用跟蹤/監(jiān)控

iPhone數(shù)據(jù)使用跟蹤/監(jiān)控

繁星點點滴滴 2019-06-20 10:53:52
iPhone數(shù)據(jù)使用跟蹤/監(jiān)控我已經(jīng)搜索過這個話題,但是很少發(fā)現(xiàn)有幫助的細(xì)節(jié)。關(guān)于這些細(xì)節(jié),我嘗試編寫如下代碼。注:請將此帖子中分享的細(xì)節(jié)與其他帖子進行比較,然后再將其標(biāo)記為重復(fù),而不僅僅是主題。- (NSArray *)getDataCountersForType:(int)type {     BOOL success;     struct ifaddrs *addrs = nil;     const struct ifaddrs *cursor = nil;     const struct sockaddr_dl *dlAddr = nil;     const struct if_data *networkStatisc = nil;      int dataSent = 0;     int dataReceived = 0;     success = getifaddrs(&addrs) == 0;     if (success) {         cursor = addrs;         while (cursor != NULL) {             if (cursor->ifa_addr->sa_family == AF_LINK) {                 dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;                 networkStatisc = (const struct if_data *) cursor->ifa_data;                 if (type == WiFi) {                     dataSent += networkStatisc->ifi_opackets;                     dataReceived += networkStatisc->ifi_ipackets;                    }                 else if (type == WWAN) {                     dataSent += networkStatisc->ifi_obytes;                     dataReceived += networkStatisc->ifi_ibytes;                  }             }             cursor = cursor->ifa_next;         }         freeifaddrs(addrs);     }            return [NSArray arrayWithObjects:[NSNumber numberWithInt:dataSent], [NSNumber numberWithInt:dataReceived], nil];    }此代碼收集iPhone設(shè)備的互聯(lián)網(wǎng)使用信息(而不僅僅是我的應(yīng)用程序)?,F(xiàn)在,如果我通過WiFi或3G使用互聯(lián)網(wǎng),我只能在ifi_obytes(發(fā)送)和ifi_ibytes(收到)但我想我應(yīng)該在ifi_opackets和ifi_ipackets.還想說,如果我連接到WiFi網(wǎng)絡(luò),但不使用互聯(lián)網(wǎng),我仍然可以獲得增值ifi_obytes和ifi_ibytes.也許我在實現(xiàn)或理解上錯了。需要有人幫我。編輯:而不是AF_LINK我試過AF_INET (sockaddr_in而不是sockaddr_dl)。這會使應(yīng)用程序崩潰。
查看完整描述

3 回答

?
胡子哥哥

TA貢獻1825條經(jīng)驗 獲得超6個贊

問題是pdp_ip0是接口之一,所有pdpXXXWWAN接口專用于不同功能,語音信箱,一般網(wǎng)絡(luò)接口。

我在蘋果論壇上讀到:操作系統(tǒng)不以進程為基礎(chǔ)保存網(wǎng)絡(luò)統(tǒng)計數(shù)據(jù)。因此,這個問題沒有確切的解決辦法。但是,您可以獲取每個網(wǎng)絡(luò)接口的網(wǎng)絡(luò)統(tǒng)計信息。

總體而言en0是你的Wi-Fi界面和pdp_ip0是你的WWAN接口。

沒有好的方式來獲取信息無線/蜂窩網(wǎng)絡(luò)數(shù)據(jù),因為,特別的日期-時間!

數(shù)據(jù)統(tǒng)計(ifa_data->ifi_obytesifa_data->ifi_ibytes)是從以前的設(shè)備重新啟動存儲的。

我不知道為什么,但是ifi_opacketsifi_ipackets只為lo0(我認(rèn)為它的主要接口)。

是。然后通過WiFi也不使用互聯(lián)網(wǎng)if_iobytes值仍然存在,因為此方法提供網(wǎng)絡(luò)字節(jié)交換,而不僅僅是Internet。

#include <net/if.h>#include <ifaddrs.h>static NSString *const DataCounterKeyWWANSent = @"WWANSent";
static NSString *const DataCounterKeyWWANReceived = @"WWANReceived";static NSString *const DataCounterKeyWiFiSent = @"WiFiSent";
static NSString *const DataCounterKeyWiFiReceived = @"WiFiReceived";NSDictionary *DataCounters(){
    struct ifaddrs *addrs;
    const struct ifaddrs *cursor;

    u_int32_t WiFiSent = 0;
    u_int32_t WiFiReceived = 0;
    u_int32_t WWANSent = 0;
    u_int32_t WWANReceived = 0;

    if (getifaddrs(&addrs) == 0)
    {
        cursor = addrs;
        while (cursor != NULL)
        {
            if (cursor->ifa_addr->sa_family == AF_LINK)
            {#ifdef DEBUG                const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
                if (ifa_data != NULL)
                {
                    NSLog(@"Interface name %s: sent %tu received %tu",cursor->ifa_name,ifa_data->ifi_obytes,ifa_data->ifi_ibytes);
                }#endif

                // name of interfaces:
                // en0 is WiFi
                // pdp_ip0 is WWAN
                NSString *name = @(cursor->ifa_name);
                if ([name hasPrefix:@"en"])
                {
                    const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
                    if (ifa_data != NULL)
                    {
                        WiFiSent += ifa_data->ifi_obytes;
                        WiFiReceived += ifa_data->ifi_ibytes;
                    }
                }

                if ([name hasPrefix:@"pdp_ip"])
                {
                    const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
                    if (ifa_data != NULL)
                    {
                        WWANSent += ifa_data->ifi_obytes;
                        WWANReceived += ifa_data->ifi_ibytes;
                    }
                }
            }

            cursor = cursor->ifa_next;
        }

        freeifaddrs(addrs);
    }

    return @{DataCounterKeyWiFiSent : @(WiFiSent),
             DataCounterKeyWiFiReceived : @(WiFiReceived),
             DataCounterKeyWWANSent : @(WWANSent),
             DataCounterKeyWWANReceived : @(WWANReceived)};}

改進的復(fù)制/粘貼支持!


查看完整回答
反對 回復(fù) 2019-06-20
?
回首憶惘然

TA貢獻1847條經(jīng)驗 獲得超11個贊

重要的是要了解這些計數(shù)器是提供的從設(shè)備上一次啟動開始。

因此,為了有效地利用它們,您應(yīng)該將設(shè)備的正常運行時間與每個示例一起使用(您可以使用mach_absolute_time()-見這,這個獲得更多信息)

一旦您有了計數(shù)器示例+正常運行時間,您就可以有更好的啟發(fā)式方法來使用數(shù)據(jù).


查看完整回答
反對 回復(fù) 2019-06-20
?
喵喔喔

TA貢獻1735條經(jīng)驗 獲得超5個贊

要添加已接受的答案,重要的是要認(rèn)識到接口顯示的數(shù)據(jù)量溢出并重新啟動于0之后4 GB,尤其是當(dāng)您使用此代碼計算兩個讀數(shù)之間的差異時。這是因為ifi_obytesifi_ibytesuint_32它們的最大值是4294967295.

此外,我建議使用unsigned ints表示包含發(fā)送和接收的數(shù)據(jù)的變量。正規(guī)化ints有一個無符號整數(shù)的最大值的一半,所以當(dāng)添加ifi_obytes它可能會導(dǎo)致溢出。

unsigned int sent = 0;sent += networkStatisc->ifi_obytes;


查看完整回答
反對 回復(fù) 2019-06-20
  • 3 回答
  • 0 關(guān)注
  • 788 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號