it is the only way to get it without having to use private API's.
Actually that code does use a bit of private or undocumented API: the interface name prefixes it looks for ("pdp_ip" and "en") aren’t official API. They probably won’t change any time soon, but there’s no actual guarantee they won’t.
provide documentation on the interfaces used on the code
It’s using the old BSD function getifaddrs(3). In a command prompt, enter the command man getifaddrs to get started.
take the total Wi-Fi and cellular usage and compare it with the new one every 15 minutes
Here’s a big gotcha with that API: the returned byte count values are unsigned 32-bit integers, not 64 bits as the wrapper code suggests. So they can wrap around zero fairly often depending on data usage, and I don’t see that your code or the wrapper code handles this. With a sampling interval of 15 minutes there’s a risk of wrapping more than once between samples, which would make it impossible to track accurately. You can make this work if your sampling interval is guaranteed to be less than the time required for a single wraparound (that is, the minimum time needed to transfer 4GB of data). But if (for example) your app is waking from the background to take a sample while other apps run, then you may have trouble meeting this timing requirement.
Topic:
Programming Languages
SubTopic:
Swift
Tags: