Start a new topic

IOS CACHING

Hi,



I am trying to implement iOS Caching. I am using the tutorial mentioned on the site. Also i have set the Cache policy to both NetworkFirst and LocalFirst but data isnt being cached. If Internet is available data is fetched from the server but if i am offline i get the offline error message. So i am assuming caching isnt working. Below is my code. Please help me out if i am doing some thing wrong here as i am stuck up on this and cant figure out whats the issue. Its a simple get all query. Do i need to make any configuration else where other than this code which i am missing. Thanks in advance for your help. Azeem



-(void)GETALLCROP{

NSLog(@"GETALLCROP : ");

KCSCollection* collection = [KCSCollection collectionFromString:@"crops" ofClass:[Crops class]];

KCSCachedStore* _store = [KCSCachedStore storeWithCollection:collection options:@{KCSStoreKeyCachePolicy : @(KCSCachePolicyLocalFirst)}];

KCSQuery* query = [KCSQuery query];

[_store queryWithQuery:query withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {

if (errorOrNil != nil) {

//An error happened, just log for now

NSLog(@"GETALLCROP ERROR : %@",errorOrNil.description);

} else {

NSLog(@"Successful Load CROP: %d", [objectsOrNil count]);

if([objectsOrNil count]>0){

for(int i = 0;i
Crops * currPage = (Crops*)[objectsOrNil objectAtIndex:i];

NSLog(@"name - %@", [currPage name]);

}

}

}

} withProgressBlock:nil cachePolicy:KCSCachePolicyLocalFirst];

}

1 person has this question
1 Comment

Regardless of the policy, the operation has be successful at least once in order to get data into the cache.
Login or Signup to post a comment