我目前正在將使用ASIHTTPRequest和SBJson的項目遷移到RestKit。執行RestKit作爲NSOperartion
以前的實現是使用NSOperation來創建HTTP請求,解析JSON對象並對Core Data API進行必要的調用。
我已經重新此因素如下:
@implementation UpdateBeers
#pragma mark - NSOperation
- (void)main {
[[RKClient sharedClient] get:@"/beers" delegate:self];
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
debug(@"didLoadResponse");
}
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error {
debug(@"%@", error);
}
#pragma mark - Memory
- (void) dealloc {
[super dealloc];
}
@end
下出現在日誌
發送GET請求URL http://localhost:9091/api/test英寸HTTP正文:
問題是服務器從來沒有收到請求。
添加下列行:
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]];
到主方法的末尾解決了這個問題。
我的問題是:
我應該執行RESKIT API調用作爲的NSOperation,如果沒有什麼我在後臺撥打電話的替代品?
在此先感謝。
請參閱:http://stackoverflow.com/questions/13885295/restkit-makes-ui-unresponsive – quantumpotato 2013-05-23 18:59:09
從Restkit 0.20起,服務請求完成方法,如request:didLoadResponse :,請求:didLoadError:,objectLoader:didLoadObjects:和objectLoader:didLoadError:已被替換爲AFHTTPRequestOperation和RKObjectRequestOperation類上的完成塊。 – prodeveloper 2014-06-23 07:24:14