2014-04-17 3 views
-3

으로 추적했습니다. 에 관한 link에 대해서는 현재 iPhone 및 iPad에서 실행중인 응용 프로그램을 검색했습니다. iphone에서 실행되는 각 프로세스에 대해 wifi 및 셀룰러 인터페이스를 추적 할 수 있습니까?각 프로세스/앱에서 보내고받은 wifi 및 셀룰러 바이트 수를

+1

추가 [Wi-Fi 및 셀룰러 데이터를 추적 할 수있는 iOS 개인 프레임 워크] (0120-333-2111) – rmaddy

+2

질문을 반복하지 마십시오. – rmaddy

답변

3

당신은 데이터 카운터를 얻을이 게시물을 참조 할 수 있지만,뿐만 아니라 당신의 앱 전체 와이파이/셀룰러 데이터를위한 것입니다 iPhone Data Usage Tracking/Monitoring

편집 : 코드가 중복 가능성

- (NSArray *)getDataCounters 
{ 
BOOL success; 
struct ifaddrs *addrs; 
const struct ifaddrs *cursor; 
const struct if_data *networkStatisc; 

int WiFiSent = 0; 
int WiFiReceived = 0; 
int WWANSent = 0; 
int WWANReceived = 0; 

NSString *name=[[[NSString alloc]init]autorelease]; 

success = getifaddrs(&addrs) == 0; 
if (success) 
{ 
    cursor = addrs; 
    while (cursor != NULL) 
    { 
     name=[NSString stringWithFormat:@"%s",cursor->ifa_name]; 
     NSLog(@"ifa_name %s == %@\n", cursor->ifa_name,name); 
     // names of interfaces: en0 is WiFi ,pdp_ip0 is WWAN 

     if (cursor->ifa_addr->sa_family == AF_LINK) 
     { 
      if ([name hasPrefix:@"en"]) 
      { 
       networkStatisc = (const struct if_data *) cursor->ifa_data; 
       WiFiSent+=networkStatisc->ifi_obytes; 
       WiFiReceived+=networkStatisc->ifi_ibytes; 
       NSLog(@"WiFiSent %d ==%d",WiFiSent,networkStatisc->ifi_obytes); 
       NSLog(@"WiFiReceived %d ==%d",WiFiReceived,networkStatisc->ifi_ibytes); 
      } 

      if ([name hasPrefix:@"pdp_ip"]) 
      { 
       networkStatisc = (const struct if_data *) cursor->ifa_data; 
       WWANSent+=networkStatisc->ifi_obytes; 
       WWANReceived+=networkStatisc->ifi_ibytes; 
       NSLog(@"WWANSent %d ==%d",WWANSent,networkStatisc->ifi_obytes); 
       NSLog(@"WWANReceived %d ==%d",WWANReceived,networkStatisc->ifi_ibytes); 
      } 
     } 

     cursor = cursor->ifa_next; 
    } 

    freeifaddrs(addrs); 
}  

return [NSArray arrayWithObjects:[NSNumber numberWithInt:WiFiSent], [NSNumber numberWithInt:WiFiReceived],[NSNumber numberWithInt:WWANSent],[NSNumber numberWithInt:WWANReceived], nil];} 
+0

이 링크는 질문에 대답 할 수 있지만 답변의 핵심 부분을 여기에 포함시키고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – gotqn

+0

참고로 찍은 덕분에 – wootage

+0

+1이 개선되었습니다. – gotqn