iPhone Data Usage Tracking/Monitoring

前端 未结 7 1280
感情败类
感情败类 2020-11-22 04:08

I\'ve searched over this topic but found very few details which were helpful. With these details I\'ve tried to cook some code as follows.

Note: Please compa

7条回答
  •  情话喂你
    2020-11-22 04:27

    To add to the accepted answer, its important to realize that the amount of data displayed by the interface overflows and restarts at 0 after every 4 GB, especially if you are using this code to calculate the difference between two readings. This is because ifi_obytes and ifi_ibytes are uint_32 and their max value is 4294967295.

    Also, I recommend using unsigned ints for the variables containing the data sent and received. Regular ints have half the max value of an unsigned integer, so when adding ifi_obytes, it may cause an overflow.

    unsigned int sent = 0;
    sent += networkStatisc->ifi_obytes;
    

提交回复
热议问题