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 limit byte)-the amount of data 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.
- // This will control the request traffic under the WWAN connection to the predefined value)
- // Requests for Wi-Fi connections will not be affected
- // This method is only available on iOS
- [ASIHTTPRequest setShouldThrottleBandwidthForWWAN: YES];
- // This will control the request traffic under the WWAN connection to the custom value)
- // This method is only available on iOS
- [ASIHTTPRequest throttleBandwidthForWWANUsingLimit: 14800];
- // This will control the traffic of mobile applications to a predefined value.
- // All requests are restricted, regardless of whether the request is connected to Wi-Fi or not.
- [ASIHTTPRequest setMaxBandwidthPerSecond: ASIWWANBandwidthThrottleAmount];
- // Records the number of bytes of traffic per second (average value in the past five seconds)
- NSLog (@ "% qi", [ASIHTTPRequest averageBandwidthUsedPerSecond]);
IMPORTANT: Before enabling traffic control, see the following items:
- The traffic control feature is a test 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.