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];
}
이것 좀 봐 - http://stackoverflow.com/questions/26675427/wrong-status-for-reachability-in-appdidbecomeactive/26675493#26675493 – Kampai
당신은 신호 강도가 연결 속도를 결정한다는 것을 암시하는 것 같습니다. 어느 것을 묻고 있습니까? 하나를 선택. –
@JonathonReinhart 귀하의 회신에 감사드립니다. 나는 신호 강도를 계산할 필요가있다. 와이파이가 높은 대역폭 너비의 비디오 플레이어를 표시 해야하는 경우. 낮은 대역폭을 가진 와이파이라면 저 대역폭 비디오 플레이어를 재생해야합니다. 그래서 내가 왜 와이파이를 계산할 필요가있다. 3g 신호 강도 (MBPS 단위) – Surya