如何使用 AFHTTPRequestOperation 更新 MBProgressHud
为了学习Ios,我下载了一些例子。
示例包括:
- AFNetworking;
- 应用内购买(来自 RayW);
- MBProgressHud;
在我的视图控制器中,我按下一个 UI 按钮,该按钮会触发应用内购买单例示例,并开始使用 AFHTTPRequestOperation 从我的服务器下载文件。这部分的沟通是有效的。但我想要实现的是在下载时更新我的HUD。由于文件>10Mb。
那么,问题是如何根据下载进度更新HUD?我试着把它画下来。
我按下 Viewcontroller 中的按钮,HUD 将显示;
-->请求将发送到处理网络部分的 Singleton InApp 帮助程序类;
-->之后,将在单例类中调用 AFHTTPRequestOperation 来下载文件;
- --->在此下载过程中,我使用 setDownloadProgressBlock 方法来获取进度。
但是我如何将进度信息发送回视图控制器中的HUD?
谢谢。
I downloaded some examples in order to learn Ios.
The examples include:
- AFNetworking;
- Inapp purchase (from RayW);
- MBProgressHud;
In my viewcontroller i push a UIbutton which triggers the Inapp purchase Singleton example and start download a file from my server with AFHTTPRequestOperation. This part of communication works. But what i want to achieve is to have my hud updated while downloading. As the file is >10Mb.
So, the question is how do i update the hud with the progress of the download? I try to draw it down.
I push the button in Viewcontroller and the hud will displayed;
--> request will sent to the Singleton InApp helper class which handles the networking part;
--> After that the AFHTTPRequestOperation will be called inside the singleton class for the download of file;
- ---> During this download i use the setDownloadProgressBlock method for the progress.
But how do i sent the progress info back to my hud in the viewcontroller?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我按照 @mattt 建议对类似问题所做的处理。
我的 Singleton InApp helper 具有
productDownloadURL
ivar 和一个prepareForDownload
方法,该方法将AFHTTPRequestOperation
返回给调用者:我的 >RootViewController 使用
AFHTTPRequestOperation
发出请求并设置downloadProgress
/success
/failure
块如下:hud 是一个 MBProgressHUD。您还可以使用
MBProgressHUDModeDeterminate
模式增强进度显示。This is what I did with a similar problem, following @mattt advice.
My Singleton InApp helper has
productDownloadURL
ivar and aprepareForDownload
method that returns anAFHTTPRequestOperation
to the caller:My RootViewController make the request by using
AFHTTPRequestOperation
and setsdownloadProgress
/success
/failure
blocks as below:hud is a MBProgressHUD. You could also enhance the progress display using
MBProgressHUDModeDeterminate
mode.从控制器发出请求,并在创建操作并将其排入变量时保留对操作的引用(您可以通过使用
HTTPOperationWithRequest:success:failure
创建中间操作对象来完成此操作,然后手动在enqueueHTTPOperation:
的主体中,设置进度视图的
progress
属性(需要划分)bytesReceived
通过bytesExpectedToReceive
以便在 0.0 和 1.0 之间标准化。Make the request from a controller, and keep a reference to the operation when you create and enqueue it in a variable (you can do this by creating an intermediary operation object with
HTTPOperationWithRequest:success:failure
, and manually doingenqueueHTTPOperation:
.In the body of
setDownloadProgressBlock
, set theprogress
property of the progress view (you need to dividebytesReceived
bybytesExpectedToReceive
in order to normalize between 0.0 and 1.0.