ios - 如何在 iOS 中检测 wifi 或 3G 信号强度?
<p><p>我正在使用 iOS 中的 MPMediaplayer 框架开发视频播放器,我需要在我的应用程序中播放两个视频。(即当用户有强网络信号时,我的第一个视频将播放)。
我的第二个视频播放器将在他们的网络低时播放。我需要在 wifi 或 3G 等中播放我的视频......我的第一件事是如何检测我的 iphone 手机中的 wifi 速度和 3G 速度。我需要以 MBPS 为单位获得移动 wifi 速度。我正在尝试编写一些代码。但这对我不起作用。提前致谢。</p>
<pre><code>#import "Reachability.h"
@interface NetworkViewController ()
@end
@implementation NetworkViewController
- (void)viewDidLoad
{
;
self.view.backgroundColor = ;
;
networkLabel = [initWithFrame:CGRectMake(20, 100, 300, 40)];
networkLabel.textColor = ;
networkLabel.backgroundColor = ;
networkLabel.userInteractionEnabled = NO;
networkLabel.text = myNewString;
;
}
- (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=[init];
success = getifaddrs(&addrs) == 0;
if (success)
{
cursor = addrs;
while (cursor != NULL)
{
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 ()
{
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 = ;
networkLabel.text = myNewString;
}
if ()
{
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 , ,,, nil];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以播放 wifi 的高分辨率视频和蜂窝数据的低分辨率视频。</p>
<pre><code>Reachability *reachability = ;
;
NetworkStatus status = ;
if(status == NotReachable)
{
//No internet
}
else if (status == ReachableViaWiFi)
{
//WiFi Play high resolution video
}
else if (status == ReachableViaWWAN)
{
//3G Play low resolution video
}
</code></pre>
<p>如果您将通过 3g 网络传输高分辨率视频,Apple 可以拒绝您的应用。</p></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 中检测 wifi 或 3G 信号强度?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27631996/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27631996/
</a>
</p>
页:
[1]