iPhone数据使用跟踪/监控
注:请将此帖子中分享的细节与其他帖子进行比较,然后再将其标记为重复,而不仅仅是主题。
- (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]; }
ifi_obytes
ifi_ibytes
ifi_opackets
ifi_ipackets
.
ifi_obytes
ifi_ibytes
.
AF_LINK
AF_INET
(sockaddr_in
sockaddr_dl
胡子哥哥
回首忆惘然
喵喔喔