【发布时间】:2011-08-02 22:18:14
【问题描述】:
如果服务器调用耗时超过 10 秒,我需要设置一个 NSTimer 对象来手动超时(Restkit 不支持)
这是我下面的代码。本质上,我的加载器类将使用 loadObjectsAtResourcePath 委托请求
如果需要超过 10 秒,我想调用 Restkit 在服务器遇到错误时调用的相同失败方法 (didFailWithError)
但我觉得我做错了,而且失败方法需要一个只在委托类中初始化的对象。
//CLASS FOR LOADING OBJECTS
-(void)getObjects{
RKObjectManager *sharedManager = [RKObjectManager sharedManager];
// loads the object via delegate
[sharedManager loadObjectsAtResourcePath:self.resourcePath delegate:self];
//creates an error
NSError *error = [NSError errorWithDomain:@"world" code:200 userInfo:nil];
// Setting timeout here. goto failure
nTimer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self.delegate selector:@selector:(objectLoader:nil didFailWithError:error:) userInfo:nil repeats:NO];
}
// handles failure
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
..
}
// handles success
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
..
}
这样做的正确方法是什么?
【问题讨论】:
标签: iphone objective-c nsurlconnection nstimer restkit