简体   繁体   English

iOS 7中是否有蜂窝数据使用API​​?

[英]Is there a cellular data usage API in iOS 7?

iOS 7 introduced a new user configuration to disable cellular data for specific apps. iOS 7引入了新的用户配置来禁用特定应用的蜂窝数据。 It can be configured in "Settings"->"Cellular" and then scrolling down. 它可以在“设置” - >“蜂窝”中配置,然后向下滚动。

设置截图

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? 那有API吗? 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. 我只对我的应用程序使用感兴趣。

There is no API to detect your download consumption or whether cellular is active for your app. 没有API可以检测您的下载消费或您的应用是否有活动状态。

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. 如果您的应用尝试连接到某个网站,但手机已关闭,则iOS可能会要求用户重新启用手机。 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. 我不确定它是如何工作的,但它可能类似于iOS 6“无网络连接”警报,如果没有连接但应用程序试图访问互联网,它会弹出。

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. 您可以检查当前的互联网连接是通过WiFi还是Cellular,但如果禁用了Cellular,您将被告知没有网络连接。

More details here: iOS Detect 3G or WiFi 更多细节: iOS检测3G或WiFi

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. 最接近的是,您可以使用SCNetworkReachability kSCNetworkReachabilityFlagsIsWWAN标志检查特定主机是否可通过蜂窝连接访问。
  • Additionally, you can enable/disable cellular data for specific connections using the NSURLRequest allowsCellularAccess property. 此外,您可以使用NSURLRequest allowsCellularAccess属性为特定连接启用/禁用蜂窝数据。

Reference: https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/Platform-SpecificNetworkingTechnologies/Platform-SpecificNetworkingTechnologies.html 参考: 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 这个答案表明如何在系统范围内测量数据使用情况: iPhone数据使用跟踪/监控

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM