Get data usage of an iPhone using ifadders

I am using ifadders to get the total amount of data used by an iphone . The counters return the total number of bytes used up ( sent & received ) perfectly . But my question is that the unsigned int data type of the counters ( max. value 4,294,967,295 ) can return the data till 4GB after which the counter overflows and so , I wanted to know if there is a way to get the counters to continuously give the data usage instead of any manual work around. And how can the ifi_obytes and ifi_ibytes can be resetted to zero without the device needed to restart ?

Replies

The statistics returned by

getifaddrs
are grandfathered in from a bygone age and, as such, have some serious limitations (as you’ve noticed, they wrap at 4 GiB and get reset on restart). There’s no good way to work around these issues. Right now your only option is to:

If you do file an enhancement request, please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The enhancement request is filed and the bug number is 29718457

I needed to ask you that if it cannot be done that way and I have to live with the limitations , Apple must have a way to get the data usage of the device for the developers ? I would like to get enlightened .

The enhancement request is filed and the bug number is 29718457

Thanks.

I needed to ask you that if it cannot be done that way and I have to live with the limitations , Apple must have a way to get the data usage of the device for the developers ?

I’m not sure I understand this question. I suspect you’re asking how Apple’s own apps (like Settings) get this information, in which case the answer is simple: apps built in to the system have access to lots of private system facilities that your apps don’t have access to.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

No Eskimo . I wanted to ask if there is any other way to get the data usage of the device instead of ifadders . As in , the number of bytes sent and received or in whatever way possible . I didn't intend to ask how do settings app get the data usage .

I wanted to ask if there is any other way to get the data usage of the device instead of ifadders.

OK, then I’ve already answered your question with my Oct 27 post.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo ,

I wanted to ask that eventhough ifaddrs have limitations , There is another structure named if_data64 inside if_var.h file which has the same members as if_data and return the data in u_int64_t datatype which solves the 4gb problem . However , When I get data from these counters , I get garbage values all the time . Can you please explain me this behaviour as it is poorly documented ? And I hav received no responses for the bug that I have filed (Stated above).

if_data64
is used by an extended version of the low-level interface that
getifaddrs
is layered on top of. If you really want to see how it works you can take a look at the Darwin source for
getifaddrs
and the corresponding code within the kernel. However, I have to caution you here: you’re straying off the path of normal iOS app development, where you may run into all sorts of pitfalls. For example:
  • It may not be able to access these low-level interfaces with the declarations in the iOS SDK. You might be tempted to copy those declarations from the macOS SDK, or from Darwin itself. Don’t do that; such techniques are definitely not supported.

  • Over time the iOS sandbox gets stricter, which makes it harder and harder for apps to implement system management functionality like this.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I came across this post while searching for if_data64 for a Mac app I'm currently writing. On the Mac, this works and is well documented in the man page for ifmib, which even contains a code example.

On iOS it is exactly as eskimo said though, you need to import headers from the macOS SDK to make the code compile, but at runtime it will fail with an EPERM error (Operation not permitted).