0
I want to cache my Wordpress JSON API in my app. I want a cache of tableview cells
and UIWebView
for when in airplane mode or off or with bad signal, the user can still see. I tried to cache with Afnetworking and Nsurlcache but I don’t know how. How can I format Afnetworking or Nsurlcache for this?
NSURL *blogURL =[NSURL URLWithString:@"http://purpledrop.org/api/get_recent_summary/"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDownloadTask *task = [session downloadTaskWithURL:blogURL completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSData *jsonData = [[NSData alloc] initWithContentsOfURL:location];
//this app would crash without this code below in airplane mode or no wifi
if (jsonData ==nil) {
return;
}
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.blogPosts = [NSMutableArray array];
NSArray *blogPostArray = [dataDictionary objectForKey:@"posts"];
for (NSDictionary *bpDictionary in blogPostArray) {
BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]];
blogPost.author = [bpDictionary objectForKey:@"author"];
blogPost.thumbnail = [bpDictionary objectForKey:@"thumbnail"];
blogPost.date = [bpDictionary objectForKey:@"date"];
blogPost.url = [NSURL URLWithString:[bpDictionary objectForKey:@"url"]];
[self.blogPosts addObject:blogPost];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}];
[task resume];
}
Hi guy will help or criticize me. I know how to speak and read. But no one answered me in English so I went here. I also wanted to help this site because it doesn’t have as many questions as the normal site.
– LazerStackr
Okay, sorry for the misunderstanding. And Ricardo’s answer, did not help? . . . Unfortunately iOS is not my area, if it were cache in WP could be. Good luck! . . . . PS: I deleted my previous comment, which mentioned the duplicate post on the website in English.
– brasofilo