Cocoa File Upload with Progress Bar

前提是你 提交于 2019-12-06 04:30:14

NOTE - unfortunately this post is of only historic interest as, sadly, ASIHttpRequest stopped development after some years. A tragedy for the community.

The best answer today (2014) is: "simply, you must use one of the libraries available to do this."

It would be, literally, crazy to "roll your own" when there are perfect libraries out there, with literally 10+ man-years of development behind them. So, find a library (sadly not ASIHttpRequest any more!) Hope it helps!


Simply use ASIHttpRequest. It's the most-used library in all of iOS and the usual networking library on Mac.

Progress tracking is built-in. It is utterly trivial to use.

Don't forget to make a small donation to the guy if you can - if he stops developing it we're all stuffed!

If you want to use just Cocoa to do this (and I agree that ASIHTTPRequest is excellent), you'll need to do the post asynchronously. The example code you've posted here is synchronous.

This just means that you'll need to implement some of the delegate methods of NSURLConnection to handle information about how your upload is progessing. In particular, implementing the method connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite: will enable you to update on progress in your UI.

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