我搜索了这个主题,但发现很少有帮助的细节.有了这些细节,我试着按如下方式编写一些代码.
注意:请将此帖中分享的详细信息与其他帖子进行比较,然后再将其标记为DUPLICATE,而不仅仅是主题.
- (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 …Run Code Online (Sandbox Code Playgroud) 我试图理解像DataMan这样的应用程序是如何工作的.即使它在后台运行,它如何衡量其他应用程序的带宽分配?