0

I would like to track a systems cellular data usage.

I found some interesting resources. The code in the accepted answer works fine and I'm able to read the bytes downloaded over the cellular network.

But I also found out that the data is reset when the user reboots their device. So, when the user opens up the app, I might (for example) read 200 MB data usage. The app saves this value. If the user closes their app, downloads another 100 MB and then reboots the device, when the app is opened again the counter will read 0 MB. The last saved value is 200 MB. How can I find out that he actually downloaded a total of 300 MB?

Community
  • 1
  • 1
Raphael
  • 3,846
  • 1
  • 28
  • 28

1 Answers1

0

You can track data usage while your app is in use. You cannot access download information when your app is not running. iOS prevents it for security reasons. You could save the value of 200MB to NSUserDefaults or another persistent store. Then you could reload that data on app launch.

Jeremiah
  • 1,471
  • 1
  • 13
  • 22
  • Exactly. But when I reload the data, it reads 0 bytes since the user rebooted his device meanwhile. The question was how to get the information about the 300 MB. – Raphael Aug 12 '15 at 06:17
  • Like i said. It is impossible. The only thing you can do is store the 200MB. You cannot get access to data usage outside of the app. – Jeremiah Aug 12 '15 at 15:31
  • Ok. I wonder how apps like DataMan doing it. They don't use a VPN and obviously no private APIs. There must be a away to get the data.. – Raphael Aug 12 '15 at 17:09
  • Ok, I just found this thread: http://stackoverflow.com/questions/10828762/ios-background-polling-without-location-services I guess this is what I need to know. How do they perform background tasks. – Raphael Aug 12 '15 at 17:21
  • You can read more about background threads here: http://www.raywenderlich.com/29948/backgrounding-for-ios , though as it said in the link their app got removed / rejected for trying to do a similar thing. – Jeremiah Aug 12 '15 at 17:23
  • http://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial I could imagine that the new mode fetch could help me here. – Raphael Aug 13 '15 at 07:21