Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a cellular data usage API in iOS 7?

Tags:

ios

ios7

iOS 7 introduced a new user configuration to disable cellular data for specific apps. It can be configured in "Settings"->"Cellular" and then scrolling down.

settings screenshot

You'll find a switch for each installed app and can see how much cellular data it has consumed.

How can I programmatically test if the switch is turned on for my app? Is there an API for that? Can I determine how much data my app has used over cellular?

I'm not asking to get the values for all apps. I'm only interested in my apps usage.

like image 479
Klaas Avatar asked Oct 03 '13 23:10

Klaas


People also ask

Where do I find my data usage on iPhone 7?

To see how much cellular data you've used, go to Settings > Cellular or Settings > Mobile Data.

How do I control data usage on my iPhone 7?

To set options when Cellular Data is on, go to Settings > Cellular > Cellular Data Options, then do any of the following: Reduce cellular usage: Turn on Low Data Mode, or tap Data Mode, then choose Low Data Mode. This mode pauses automatic updates and background tasks when iPhone isn't connected to Wi-Fi.

What is iOS cellular data?

Cellular Data connects your iPhone to the internet when you're not connected to Wi-Fi. When Cellular Data isn't on, your iPhone can't access the internet when you're on the go.

How can I tell what apps are using cellular data?

In Settings, choose “Cellular.” When you're in Cellular settings, you'll see several options with switches. Scroll down below that and you'll find a list of apps installed on your cell phone. They are sorted by how much cellular data they have been using, with heavy offenders at the top of the list.


2 Answers

There is no API to detect your download consumption or whether cellular is active for your app.

If your app tries to connect to a website, but cellular is turned off, then iOS may ask the user to turn cellular back on. I'm not exactly sure how that works, but it is probably similar to the iOS 6 "no network connection" alert that would pop up if there is no connection but an app tries to access the internet.

You can check if the current internet connection is over WiFi or Cellular, but if Cellular is disabled you will just be told that there is no network connection.

More details here: iOS Detect 3G or WiFi

like image 89
Abhi Beckert Avatar answered Sep 24 '22 12:09

Abhi Beckert


You can't check if the cellular data switch is turned on.

  • The closest thing is that you can check if a specific host is reachable over cellular connection using the SCNetworkReachability kSCNetworkReachabilityFlagsIsWWAN flag.
  • Additionally, you can enable/disable cellular data for specific connections using the NSURLRequest allowsCellularAccess property.

Reference: https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/Platform-SpecificNetworkingTechnologies/Platform-SpecificNetworkingTechnologies.html

This answer suggests how data usage can be measured system-wide: iPhone Data Usage Tracking/Monitoring

like image 21
jrc Avatar answered Sep 23 '22 12:09

jrc