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/