2014-12-24 2 views
3

iOS에서 MPMediaplayer 프레임 워크를 사용하는 동영상 플레이어에서 작업 중이므로 앱에서 두 개의 동영상을 재생해야합니다. 즉, 사용자가 강력한 네트워크 신호를 사용하면 내 첫 번째 동영상이 재생됩니다. 두 번째 비디오 플레이어는 네트워크가 낮을 때 재생됩니다. 나는 와이파이 또는 3G 등에서 내 비디오를 재생해야합니다 ... 내 첫 번째 것은 내 아이폰 모바일 및 3G 속도 내 와이파이 속도를 감지하는 방법입니다. MBPS로 모바일 와이파이 속도를 얻어야합니다. 나는 약간의 코드를 작성하려고했다. 그러나 그것은 나를 위해 일하지 않습니다. 미리 감사드립니다.iOS에서 Wi-Fi 또는 3G 신호 강도를 감지하는 방법은 무엇입니까?

#import "Reachability.h" 

@interface NetworkViewController() 

@end 

@implementation NetworkViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad];  
    self.view.backgroundColor = [UIColor whiteColor]; 
    [self getDataCounters]; 

    networkLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 300, 40)]; 
    networkLabel.textColor = [UIColor blackColor]; 
    networkLabel.backgroundColor = [UIColor whiteColor]; 
    networkLabel.userInteractionEnabled = NO; 
    networkLabel.text = myNewString; 

    [self.view addSubview:networkLabel]; 
} 

- (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]; 
    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); 
         NSLog(@"wifi data is %.2f",(float)WiFiReceived/1048576); 

        myNewString = [NSString stringWithFormat:@"%2f", (float)WiFiReceived/1048576]; 
        networkLabel.text = myNewString; 
       } 

       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

이것 좀 봐 - http://stackoverflow.com/questions/26675427/wrong-status-for-reachability-in-appdidbecomeactive/26675493#26675493 – Kampai

+1

당신은 신호 강도가 연결 속도를 결정한다는 것을 암시하는 것 같습니다. 어느 것을 묻고 있습니까? 하나를 선택. –

+0

@JonathonReinhart 귀하의 회신에 감사드립니다. 나는 신호 강도를 계산할 필요가있다. 와이파이가 높은 대역폭 너비의 비디오 플레이어를 표시 해야하는 경우. 낮은 대역폭을 가진 와이파이라면 저 대역폭 비디오 플레이어를 재생해야합니다. 그래서 내가 왜 와이파이를 계산할 필요가있다. 3g 신호 강도 (MBPS 단위) – Surya

답변

2

셀룰러 데이터의 Wi-Fi 및 저해상도 비디오를위한 고해상도 비디오를 재생할 수 있습니다.

Reachability *reachability = [Reachability reachabilityForInternetConnection]; 
[reachability startNotifier]; 

NetworkStatus status = [reachability currentReachabilityStatus]; 

if(status == NotReachable) 
{ 
    //No internet 
} 
else if (status == ReachableViaWiFi) 
{ 
    //WiFi Play high resolution video 
} 
else if (status == ReachableViaWWAN) 
{ 
    //3G Play low resolution video 
} 

3g 네트워크에서 고해상도 비디오를 스트리밍하는 경우 Apple에서 앱을 거부 할 수 있습니다.

+0

답장을 보내 주셔서 감사합니다 ..하지만 나는 장치 bandwith을 얻을 필요가 ... 그래서 plz 가이드 날이 일을 할 수 있습니까? 장치 대역 너비에 따라 비디오 플레이어를 재생해야합니다. 내가 높은 대역 너비를 가지고 있다면 고 대역 너비의 비디오 플레이어를 재생할 필요가 있습니다. 낮은 대역폭을 얻었고 낮은 대역폭을 재생해야합니다. – Surya

+0

Apple에서 제공하는 API 또는 라이브러리가 없습니다. 당신은 당신의 장치의 인터넷 연결의 대역폭을 알기위한 webservice 전화를해야합니다. – abhishekkharwar

+0

webservices ?? webservices를 기반으로 모바일 Wi-Fi 대역폭을 확보 할 수 있습니까? – Surya

관련 문제