13

Is there a way to track cellular data usage on iPhone ? There are lot of apps which does the same like 'Dataman' and 'DataUsage'

Basically I am looking for a programmatic way to get information stored in Settings -> General -> Usage

Any help will be appreciated.

Unicorn
  • 2,382
  • 6
  • 29
  • 42
  • I also asked this, but no reply yet: http://stackoverflow.com/questions/5274805/iphone-ipad-data-usage-tracking http://stackoverflow.com/questions/4375441/how-to-keep-track-of-the-network-traffic-on-3g-wifi-on-an-ios-device http://stackoverflow.com/questions/4380806/iphone-data-usage-monitoring http://stackoverflow.com/questions/4746053/how-does-dataman-iphone-app-work-in-the-background – phi Jul 07 '11 at 07:33
  • @Irene: hmm, this is bad because I see apps in app store doing same functionality..!!! – Unicorn Jul 07 '11 at 07:38
  • Check also http://stackoverflow.com/questions/4313358/measure-network-traffic-programmatically-on-iphone - they suggest getifaddrs but I haven't been able to find a working example.. – phi Jul 07 '11 at 07:57
  • Same here. I also don't get any answers see [this](http://stackoverflow.com/q/11465566/1132951) – The iOSDev Jul 13 '12 at 10:42
  • 1
    Hi @Nate For Data Usage Check This [Data Usage][1] [1]: http://stackoverflow.com/questions/7946699/iphone-data-usage-tracking-monitoring/8014012#8014012 – Sandeep Khade Jan 28 '13 at 11:56

2 Answers2

7

To check Cellular Network Use this

- (bool) hasCellular {
    struct ifaddrs * addrs;
    const struct ifaddrs * cursor;
    bool found = false;
    if (getifaddrs(&addrs) == 0) {
        cursor = addrs;
        while (cursor != NULL) {
            NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
                if ([name isEqualToString:@"pdp_ip0"]) 
                    found = true;
            }
            cursor = cursor->ifa_next;
        }
        freeifaddrs(addrs);
    }
    return found;
}
Esha
  • 1,328
  • 13
  • 34
Sandeep Khade
  • 2,832
  • 3
  • 21
  • 37
  • I don't think Unicorn wants to know that the device is connected to the cellular network. I think they're interested in **how much** data has gone through that interface. – Nate Jan 28 '13 at 09:29
  • 6
    http://stackoverflow.com/questions/7946699/iphone-data-usage-tracking-monitoring/8014012#8014012 check this for data usage – Sandeep Khade Jan 28 '13 at 11:57
2

You could query each network interface for the data going through it.

Eric
  • 2,045
  • 17
  • 24