Reputation: 175
I am building an application that utilizes restkit for IOS. I am having problems in the cache area i believe. I setup my app for the initial startup to get a load of data and map it into core data using restkit. Everything works fine and the data is shown in a table view. Now if I make the app go to the background and then click the app again to resume I call the same method to load the data but this time i send version #'s to the server to only get back objects that have changed,added or deleted since the last pull. This all maps fine but when I go to display these objects I get the same data that was in the first pull. I believe it might be a clearing of the cache problem but i dont know. Help is grateful.
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;
}];
Upvotes: 0
Views: 290
Reputation: 175
You just need to save it in object loader delegate method.
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
[[RKObjectManager sharedManager].objectStore.managedObjectContextForCurrentThread save:nil];
}
Upvotes: 1