3

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

详细信息:http: //blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/#Operation_freezing

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

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

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

4

1 回答 1

4

我想出的最佳答案是继承 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;
于 2012-07-17T00:58:55.190 回答