iOS:如何检查应用的蜂窝数据使用情况?

问题描述:

在我的应用程序中,我希望能够检测特定应用程序的蜂窝数据使用情况,并根据检查行为的结果进行适当的调整。iOS:如何检查应用的蜂窝数据使用情况?

有没有办法执行这个程序化检查?

+0

**答案**:使用有据可查的[Apple提供的可达性框架](https://developer.apple.com/library/ios/samplecode/reachability/introduction/intro.html)。 – esqew 2014-11-06 02:38:18

转到以下链接:

https://developer.apple.com/library/ios/samplecode/reachability/introduction/intro.html

下载并导入头和iplementation文件,然后使用此代码:

Reachability *reachability = [Reachability reachabilityForInternetConnection]; 
NetworkStatus status = [reachability currentReachabilityStatus]; 

if (status == ReachableViaWWAN) 
{ 
    NSLog(@"Cellular data"); 
} 

这个项目是一个小老头,你可能需要关闭ARC模式看到这个答案:

How can I disable ARC for a single file in a project?

+2

谢谢你的回答!但是这个代码检查蜂窝是否打开。它不检查手机上安装的特定应用程序的蜂窝数据是否已打开。 – 2014-11-06 03:37:00