获取的是开机后WIFI,3G/GPRS网络下使用流量(仅仅只能获取开机后的)
和一个应用"瓦力流量仪"类似.
瓦力流量仪的核心代码也就是这一段吧!
需要引入
#include
#include
#include
#include
+ (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 =