我正在尝试发出 3 个单独的 reskit 请求,以获得 JSON 响应。
我找不到关于如何实现 restkit enqueueBatchOfObjectRequestOperations 方法的明确答案。
有没有人有一些使用它的示例代码?
我有 3 种与此类似的单独方法:
- (void)getRacks
{
RKObjectMapping *deviceRackMapping = [RKObjectMapping mappingForClass:[DeviceRack class]];
[deviceRackMapping addAttributeMappingsFromDictionary:@{
@"id": @"deviceRackID",
@"dataCenterID": @"data_center_id",
@"number": @"deviceRackNumber",
}];
//Mapping of nested data center object
RKObjectMapping *dataCenterMapping = [RKObjectMapping mappingForClass:[DataCenter class]];
[dataCenterMapping addAttributeMappingsFromDictionary:@{
@"id": @"dataCenterID",
@"name": @"dataCenterName",
@"shortname": @"dataCenterShortName",
}];
[deviceRackMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"data_center"
toKeyPath:@"dataCenter"
withMapping:dataCenterMapping]];
//Mapping of nested sites object
RKObjectMapping *siteMapping = [RKObjectMapping mappingForClass:[Site class]];
[siteMapping addAttributeMappingsFromDictionary:@{
@"id": @"siteID",
@"name": @"name",
@"shortname": @"shortName",
}];
[deviceRackMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"site"
toKeyPath:@"site"
withMapping:siteMapping]];
//Fetch array from JSON
RKObjectManager *objectManager3 = [RKObjectManager sharedManager];
[objectManager3 getObject:self.deviceRacksArray
path:[NSString stringWithFormat:@"/api/v1/device_racks"]
parameters:nil
success:^(RKObjectRequestOperation *operation3, RKMappingResult *mappingResult3)
{
self.deviceRacksArray = (NSArray *)[mappingResult3 array];
}
failure:^(RKObjectRequestOperation *operation3, NSError *error)
{
//errorMessageLabel.text = [error localizedDescription];
NSLog(@"Error: %@", [error localizedDescription]);
}];
}
我有这个方法的 3 个单独版本,每个版本都viewDidLoad
通过调用来调用[self getSites]
,我看到的问题是我必须将请求排队。我找不到任何示例代码来显示我应该在何时何地对一批对象请求进行排队。我会满足于 3 个单独的连接,但它似乎不允许这样做。
在将数组发送到 UIPickerView 作为数据源之前,我会调用这些方法中的每一个。
任何帮助,将不胜感激。