IOS怎么获取当前网速
巴扎黑
巴扎黑 2017-04-17 17:46:31
0
2
448

我想在app里实时看到当前手机的网速,比如下载视频等等,我想要实时显示当前手机网速;请问如何实现?

巴扎黑
巴扎黑

reply all(2)
Ty80
1、自己下载速度这种,可以直接在接受数据的地方加统计
2、获取全局的数据,可以监控网卡的进出流量
/*获取网络流量信息*/
+ (long long) getInterfaceBytes
{
    struct ifaddrs *ifa_list = 0, *ifa;
    if (getifaddrs(&ifa_list) == -1)
    {
        return 0;
    }
    
    uint32_t iBytes = 0;
    uint32_t oBytes = 0;
    
    for (ifa = ifa_list; ifa; ifa = ifa->ifa_next)
    {
        if (AF_LINK != ifa->ifa_addr->sa_family)
            continue;
        
        if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING))
            continue;
        
        if (ifa->ifa_data == 0)
            continue;
        
        /* Not a loopback device. */
        if (strncmp(ifa->ifa_name, "lo", 2))
        {
            struct if_data *if_data = (struct if_data *)ifa->ifa_data;
            
            iBytes += if_data->ifi_ibytes;
            oBytes += if_data->ifi_obytes;
        }
    }
    freeifaddrs(ifa_list);
    
    NSLog(@"\n[getInterfaceBytes-Total]%d,%d",iBytes,oBytes);
    return iBytes + oBytes;
}
PHPzhong

Do you want to monitor the whole situation or just see the speed of this app in this app?
To monitor the whole situation and see the speed of each app, you need to apply for this network control, and can you distinguish the traffic of that app? It's not clear.
If you monitor the network speed in the app, it's simple. Just write a class or method and call it for all Internet activities.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template