IOS development ASIHTTPRequest Traffic Control

Source: Internet
Author: User

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.

 
 
  1. // This will control the request traffic under the WWAN connection to the predefined value)
  2. // Requests for Wi-Fi connections will not be affected
  3. // This method is only available on iOS
  4. [ASIHTTPRequest setShouldThrottleBandwidthForWWAN: YES];
  5. // This will control the request traffic under the WWAN connection to the custom value)
  6. // This method is only available on iOS
  7. [ASIHTTPRequest throttleBandwidthForWWANUsingLimit: 14800];
  8. // This will control the traffic of mobile applications to a predefined value.
  9. // All requests are restricted, regardless of whether the request is connected to Wi-Fi or not.
  10. [ASIHTTPRequest setMaxBandwidthPerSecond: ASIWWANBandwidthThrottleAmount];
  11. // Records the number of bytes of traffic per second (average value in the past five seconds)
  12. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.