2014-11-06 63 views
4

在我的應用程序中,我希望能夠檢測特定應用程序的蜂窩數據使用情況,並根據檢查行爲的結果進行適當的調整。iOS:如何檢查應用的蜂窩數據使用情況?

有沒有辦法執行這個程序化檢查?

+0

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

回答

0

轉到以下鏈接:

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