I believe that I am a friend of IOS developers and will not be unfamiliar with the asihttprequest library. Next I will share my experiences on using asihttprequest to monitor traffic. What I need to declare in advance is only in wwan (GPRS/EDGE/3G) in the network, the traffic monitoring of asihttprequest can only take effect, but it cannot take effect in the WiFi network.
From version 1.0.7, asihttprequest can control the traffic so that the traffic of all requests does not exceed the user-defined limit. This makes it easier for iPhone programs that send/receive large amounts of data to pass Apple's App Store review.
Traffic is controlled by a global quantity limit (in bytes)-the amount of traffic that can be transferred per second. All requests share this restriction. When sending or receiving data, asihttprequest keeps track of the data volume sent/received in the last second. If one request reaches the limit, other ongoing requests will wait. On iOS, you can enable asihttprequest to automatically enable traffic control when using the wwan (GPRS/EDGE/3g) connection, and disable the traffic limit when using the WiFi connection.
The following is the specific configuration code for using asihttprequest:
// Throttling (control to a predefined value) is performed for requests over wwan connections. Requests over Wi-Fi connections are not affected, this method can only be used on iOS [asihttprequest setshouldthrottlebandwidthforwwan: Yes]; // you can set the request traffic ceiling of the wwan connection to 50kb [asihttprequest throttlebandwidthforwwanusinglimit: 50*1024 // All requests will be restricted, regardless of whether the request is connected to Wi-Fi or not. Pay attention to [asihttprequest setmaxbandwidthpersecond: asiwwanbandwidththrottleamount]; // limit the upload/download speed per second // record the number of bytes of traffic per second (average value in the past five seconds) nslog (@ "% lD", [asihttprequest averagebandwidthusedpersecond]);
Note:
Before enabling traffic control, you must note that the traffic control feature is a test-type feature: You have to take risks on your own,
Do not set the bandwidth limit very low-it is best not to be lower than asiwwanbandwidththrottleamount
The actual traffic is usually slightly higher than the traffic set by your program, because the traffic measurement does not contain the HTTP header.
The value of asiwwanbandwidththrottleamount is unofficial. As far as I know, it has not published the traffic limit.
Do not enable traffic control unless your program downloads or uploads a large amount of data. It is best to enable it when it is about to download or upload a large amount of data, and disable it at other times.
This should work according to my descriptions, but I don't guarantee that your app will not be rejected if it uses my traffic control.