IOS Development Network: asihttprequest traffic monitoring

Source: Internet
Author: User

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.

Related Article

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.