跟踪数据使用情况 [英] Track data usage

查看:163
本文介绍了跟踪数据使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试跟踪iPhone用户的数据使用情况。

I am trying to track the data usage from the user of the iPhone.

但是我很松散我发现了这个:

But I'am loose I found this:

- (NSArray *)getDataCounters {
BOOL   success;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
const struct if_data *networkStatisc; 

int WiFiSent = 0;
int WiFiReceived = 0;
int WWANSent = 0;
int WWANReceived = 0;

NSString *name=[[[NSString alloc]init]autorelease];

success = getifaddrs(&addrs) == 0;
if (success) 
{
    cursor = addrs;
    while (cursor != NULL) 
    {
        name=[NSString stringWithFormat:@"%s",cursor->ifa_name];
        NSLog(@"ifa_name %s == %@\n", cursor->ifa_name,name);
        // names of interfaces: en0 is WiFi ,pdp_ip0 is WWAN 

        if (cursor->ifa_addr->sa_family == AF_LINK) 
        {
            if ([name hasPrefix:@"en"]) 
            {
                networkStatisc = (const struct if_data *) cursor->ifa_data;
                WiFiSent+=networkStatisc->ifi_obytes;
                WiFiReceived+=networkStatisc->ifi_ibytes;
                NSLog(@"WiFiSent %d ==%d",WiFiSent,networkStatisc->ifi_obytes);
                NSLog(@"WiFiReceived %d ==%d",WiFiReceived,networkStatisc->ifi_ibytes);
            }

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

        cursor = cursor->ifa_next;
    }

    freeifaddrs(addrs);
}       

return [NSArray arrayWithObjects:[NSNumber numberWithInt:WiFiSent], [NSNumber numberWithInt:WiFiReceived],[NSNumber numberWithInt:WWANSent],[NSNumber numberWithInt:WWANReceived], nil];

}

但我该怎么办?它自动,每次用户调用Web浏览器时我都会与包的大小相交

But how could i do it automatically, each time the user call the web browser I intersect the size of the package

谢谢

推荐答案

您正在寻找记录或分析

记录:只需NSLog或写入数组并定期保存到文件

Logging : Just NSLog or write to an array and periodicly save to file

分析:查看 Flurry 这是一个很好的用户体验跟踪计划

Analytics : Check out Flurry it's a good user experience tracking program

这篇关于跟踪数据使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆