サーバーから情報を取得するために RESTKIT Object Manager を使用しています。私の実装コードのスニペットは次のとおりです。
-(void)getObjects
{
//Instantiate the RestKit Object Manager
RKObjectManager *sharedManager = [RKObjectManager sharedManager];
//show the spinner
[self showLoading];
//call server with the resourcepath
[sharedManager loadObjectsAtResourcePath:self.resourcePath delegate:self];
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
{
// handling in scenarios of empty arrays
if ( [objects count]==0 ){
[self hideLoading];
if (emptyHandler){
emptyHandler();
}else{
[self standardEmptyHandling];
}
return;
}
// planned failure
if ( [[objects objectAtIndex:0] isKindOfClass:[Failure class]]){
NSAssert([objects count]==1,@"object returned is type failure, but there are more than one object in it");
failureObject=[objects objectAtIndex:0];
[self hideLoading];
[self standardErrorHandling];
return;
}
//return completion block to caller
completionHandler(objects);
}
ただし、サーバー エラーまたは到達可能性エラーが発生し、プロセスが終了するまで長時間試行し続ける場合があります (スピナーは長時間表示されます_.
たとえば、サーバーが 20 秒以内に応答しない場合にユーザーに再試行するように警告するように、実装でタイムアウト期間を設定する方法はありますか?