ฉันกำลังทำงานกับแอป VPN อย่างรวดเร็ว 5 เรากำลังใช้ NEVPNManager เพื่อจัดการการกำหนดค่า VPN ทั้งหมด หนึ่งในคุณสมบัติที่เราต้องการคือการวัดข้อมูลการใช้งานของผู้ใช้ในขณะที่เชื่อมต่อกับ VPN ของเรา เราจะทำเช่นนี้ได้อย่างไร?
NEVPNManager - วิธีติดตามการใช้ข้อมูลของ VPN อย่างรวดเร็ว
คำตอบ (1)
NEVPNManager ไม่มีวิธีการใด ๆ ที่ตอบสนองความต้องการของคุณ ต่อไปนี้เป็นวิธีแก้ปัญหาที่ใช้เป็นการส่วนตัวในแอปพลิเคชัน
วิธีแก้ไข: ค้นหาอินเทอร์เฟซเครือข่ายที่เหมาะสมและเริ่มอ่านไบต์เข้าและออก
en0 หมายถึง Wifi pdp_ip หมายถึงเครือข่ายเซลลูล่าร์
+ (NSDictionary *) DataCounters{
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
u_int32_t WiFiSent = 0;
u_int32_t WiFiReceived = 0;
u_int32_t WWANSent = 0;
u_int32_t WWANReceived = 0;
if (getifaddrs(&addrs) == 0)
{
cursor = addrs;
while (cursor != NULL)
{
if (cursor->ifa_addr->sa_family == AF_LINK)
{
// name of interfaces:
// en0 is WiFi
// pdp_ip0 is WWAN
NSString *name = [NSString stringWithFormat:@"%s",cursor->ifa_name];
if ([name hasPrefix:@"en"])
{
const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
if(ifa_data != NULL)
{
WiFiSent += ifa_data->ifi_obytes;
WiFiReceived += ifa_data->ifi_ibytes;
}
}
if ([name hasPrefix:@"pdp_ip"])
{
const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
if(ifa_data != NULL)
{
WWANSent += ifa_data->ifi_obytes;
WWANReceived += ifa_data->ifi_ibytes;
}
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return @{DataCounterKeyWiFiSent:[NSNumber numberWithUnsignedInt:WiFiSent],
DataCounterKeyWiFiReceived:[NSNumber numberWithUnsignedInt:WiFiReceived],
DataCounterKeyWWANSent:[NSNumber numberWithUnsignedInt:WWANSent],
DataCounterKeyWWANReceived:[NSNumber numberWithUnsignedInt:WWANReceived]};}
person
munibsiddiqui
schedule
04.06.2020