ios5 - MKNetworkKit - 未调用卡住操作/onCompletion 和 onError 的跟踪状态

标签 ios5 network-programming

MKNetworkKit 库的众多强大功能之一是它可以轻松地“卡住”http POST 请求(例如上传到服务器),这些请求可以在网络连接恢复后自动恢复。

详情在这里: http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/#Operation_freezing

但是当我结束基于 MKNetworkKit 的应用程序时,我发现 onCompletion 和 onError block 不会在卡住的网络事务上被调用(这显然是一个已知问题),我正在努力构建一个围绕此的 UI,让用户知道卡住交易何时真正完成。

有没有人处理过这种情况?

让用户对网络中断和停机时间一无所知,但仍然能够就上次成功连接的时间提供一些反馈的最佳方法是什么?

最佳答案

我想出的最佳答案是子类化 MKNetworkOperation,然后覆盖 operationSucceeded 和 operationFailedWithError。当卡住操作完成时,仍会调用这些例程。

来自 MKNetworkOperation.h 头文件:

/*!
 *  @abstract Overridable custom method where you can add your custom business logic error handling
 *  
 *  @discussion
 *  This optional method can be overridden to do custom error handling. Be sure to call [super operationSucceeded] at the last.
 *  For example, a valid HTTP response (200) like "Item not found in database" might have a custom business error code
 *  You can override this method and called [super failWithError:customError]; to notify that HTTP call was successful but the method
 *  ended as a failed call
 *
 */
-(void) operationSucceeded;

/*!
 *  @abstract Overridable custom method where you can add your custom business logic error handling
 *  
 *  @discussion
 *  This optional method can be overridden to do custom error handling. Be sure to call [super operationSucceeded] at the last.
 *  For example, a invalid HTTP response (401) like "Unauthorized" might be a valid case in your app.
 *  You can override this method and called [super operationSucceeded]; to notify that HTTP call failed but the method
 *  ended as a success call. For example, Facebook login failed, but to your business implementation, it's not a problem as you
 *  are going to try alternative login mechanisms.
 *
 */
-(void) operationFailedWithError:(NSError*) error;

关于ios5 - MKNetworkKit - 未调用卡住操作/onCompletion 和 onError 的跟踪状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10855531/

相关文章:

C: 通过 execl 传递套接字连接

ios5 - IOS Storyboard 何时使用导航 Controller ?

聊天服务器(C 网络编程)

iphone - 使用 Curl 验证 App Store 收据时出现 IllegalStateException?

iphone - UTF8 iPhone 无法读取阿姆哈拉语字母

java - DEBUG/SntpClient(70) : request time failed: java.net.SocketException:Android 上的协议(protocol)不支持地址族

c - 服务器程序卡在 read() 函数上,但 write() 函数在客户端程序中运行良好

linux - 设置 linux socket - high priority 的效果是什么?

javascript - 如何在 UIWebview IOS 5 中使用 CodeMirror2 代码选择文本

iphone - 非法配置 - 静态 TableView 仅在嵌入 UITableViewController 时有效