我正在构建一个利用restkit for IOS的应用程序。我相信我在缓存区有问题。我为初始启动设置了我的应用程序以获取大量数据并使用restkit将其映射到核心数据。一切正常,数据显示在表格视图中。现在,如果我让应用程序转到后台然后再次单击应用程序以继续我调用相同的方法来加载数据但这次我将版本#'发送到服务器以仅返回已更改,添加或自上次拉动后删除。这一切都很好,但是当我去显示这些对象时,我得到的是第一次拉出的相同数据。我相信它可能是一个清除缓存问题,但我不知道。帮助很感激。
RKObjectManager * objectManager = [RKObjectManager objectManagerWithBaseURLString:@“http://link.com”]; objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES; objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@“34453434.sqlite”]; RKManagedObjectMapping * cliffMapping = [RKManagedObjectMapping mappingForClass:[Cliff class] inManagedObjectStore:objectManager.objectStore];
cliffMapping.primaryKeyAttribute = @"cliffID";
cliffMapping.rootKeyPath = @"cliffs";
[cliffMapping mapKeyPath:@"name" toAttribute:@"name"];
[cliffMapping mapKeyPath:@"cliffId" toAttribute:@"cliffID"];
[cliffMapping mapKeyPath:@"description" toAttribute:@"cliffDescription"];
[cliffMapping mapKeyPath:@"notes" toAttribute:@"notes"];
[cliffMapping mapKeyPath:@"city" toAttribute:@"city"];
[cliffMapping mapKeyPath:@"intensity" toAttribute:@"intensity"];
[cliffMapping mapKeyPath:@"latitude" toAttribute:@"latitude"];
[cliffMapping mapKeyPath:@"height" toAttribute:@"height"];
[cliffMapping mapKeyPath:@"longitude" toAttribute:@"longitude"];
[cliffMapping mapKeyPath:@"zipcode" toAttribute:@"zipcode"];
[objectManager.mappingProvider setMapping:cliffMapping forKeyPath:@"cliffs"];
[objectManager.mappingProvider addObjectMapping:cliffMapping];
RKManagedObjectMapping* stateMapping = [RKManagedObjectMapping mappingForClass:[State class] inManagedObjectStore:objectManager.objectStore];
stateMapping.rootKeyPath = @"States";
stateMapping.primaryKeyAttribute = @"stateID";
[stateMapping mapKeyPath:@"stateId" toAttribute:@"stateID"];
[stateMapping mapKeyPath:@"name" toAttribute:@"name"];
[stateMapping mapKeyPath:@"version" toAttribute:@"sversion"];
[stateMapping mapKeyPath:@"cliffAmount" toAttribute:@"cliffAmount"];
[stateMapping mapRelationship:@"cliffs" withMapping:cliffMapping];
[objectManager.mappingProvider setMapping:stateMapping forKeyPath:@"States"];
[objectManager.mappingProvider addObjectMapping:stateMapping];
[objectManager loadObjectsAtResourcePath:@"/Application/getEverything" usingBlock:^(RKObjectLoader *loader){
loader.serializationMIMEType = RKMIMETypeJSON;
loader.resourcePath = @"/Application/getEverything";
loader.method = RKRequestMethodPOST;
loader.delegate = self;
loader.objectMapping = stateMapping;
}];
答案 0 :(得分:1)
您只需将其保存在对象加载程序委托方法中即可。
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
[[RKObjectManager sharedManager].objectStore.managedObjectContextForCurrentThread save:nil];
}