0

我正在构建一个使用 restkit for IOS 的应用程序。我相信缓存区有问题。我为初始启动设置了我的应用程序,以获取大量数据并使用 restkit 将其映射到核心数据中。一切正常,数据显示在表格视图中。现在,如果我让应用程序进入后台,然后再次单击应用程序以恢复,我会调用相同的方法来加载数据,但这次我将版本号发送到服务器以仅取回已更改、添加或自上次拉取后已删除。这一切都很好,但是当我去显示这些对象时,我得到的数据与第一次拉动中的数据相同。我相信这可能是缓存问题的清除,但我不知道。帮助不胜感激。

RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURLString:@"http://link.com"]; objectManager.client.requestQueue.showsNetworkActivityIndi​​catorWhenBusy = YES; objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"34453434.sqlite"]; RKManagedObjectMapping* 悬崖映射 = [RKManagedObjectMapping mappingForClass:[悬崖类] 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;
}];
4

1 回答 1

1

您只需将其保存在对象加载器委托方法中。

- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{ 
   [[RKObjectManager sharedManager].objectStore.managedObjectContextForCurrentThread      save:nil];
}
于 2013-03-12T18:14:14.137 回答