NSURLSession bandwidth limiting

断了今生、忘了曾经 提交于 2019-12-11 02:15:50

问题


Is there a way to limit the bandwidth in NSURLSession?

I'm making file-sync-client for macOS like Dropbox/GoogleDrive/pCloud and they all have bandwidth limiting options, but I'm not sure how to configure NSURLSession to respect bandwidth limiting.


回答1:


Unless Apple has added something very recently, NSURLSession provides no facilities for bandwidth limiting. The only ways I'm aware of to do that are:

  • Use lower-level APIs that allow you to provide your own sockets and then throttle the data rate at the TCP socket level.
  • Provide an in-app web proxy and use it for all outgoing requests. Configure the proxy to limit the bandwidth of all requests that go through it.



回答2:


Looks like ASIHTTPRequest features Bandwidth throttling support. Although it may be an old library, from what I observe it's still fully functional thus it may be worth exploring.

Of course, using ASIHTTPRequest would require abandoning NSURLSession for this purpose.



来源:https://stackoverflow.com/questions/46367823/nsurlsession-bandwidth-limiting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!