I have one json url and in this url there is images urls and some data. I want to store that data and images in local and also retrieve it without net connection. I learn something about that and i get that we can store data using NSCoding but it is not work properly and Little bit complex. Is there any way getting data from cache storage than please send some link or code that help me. Right now i retrieve data and images usign Net connection but what to do when no Net connection. and yes i told you that i'm new in ios development so please send some code or link that i learn easily and impliment it. thanks!
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Enter in connectionDidFinishLoading method");
[connection release];
NSString *responseString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// NSLog(@"JSON Data =:%@",responseString);
//[jsonData writeToFile:[self mySaveFileToPath:@"wedding.json"] atomically:YES];
NSError *error;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContainers error: &error];
NSArray *jResponse = [jsonArray valueForKey:@"posts"];
NSArray *arrPosts = [jResponse valueForKey:@"post"];
for (int i= 0; i<[arrPosts count]; i++)
{
jsonObjClass = [[JSONObjClass alloc] init];
NSString *strTemp = [[arrPosts valueForKey:@"field_logo_fid"] objectAtIndex:i];
//NSLog(@"File name == %@",[strTemp lastPathComponent]);
NSLog(@"Icon name :%@",strTemp);
if (strTemp != nil)
{
jsonObjClass.fieldLogoFid = [NSString stringWithFormat:@"%@",strTemp];
}
strTemp = [[arrPosts valueForKey:@"title"] objectAtIndex:i];
if (strTemp != nil)
{
NSLog(@"In Title Check .. ");
jsonObjClass.title = [NSString stringWithFormat:@"%@",strTemp] ;
// NSData *titleData = [jsonObjClass.title dataUsingEncoding:NSSt ];
//NSKeyedArchiver *archive = [NSKeyedArchiver archivedDataWithRootObject:titleData];
//[archive encodeObject:titleData forKey:@"titleData"];
//NSLog(@"Title Data == %@",titleData);
//For saving Data...
// [[NSUserDefaults standardUserDefaults] setObject:titleData forKey:@"titleData"];
NSLog(@"After saving Data..");
}
strTemp = [[arrPosts valueForKey:@"Posted"]objectAtIndex:i];
if (strTemp != nil)
{
jsonObjClass.posted = [NSString stringWithFormat:@"%@",strTemp];
}
strTemp = [[arrPosts valueForKey:@"by"]objectAtIndex:i];
if (strTemp != nil)
{
jsonObjClass.by = [NSString stringWithFormat:@"%@",strTemp];
}
strTemp = [[arrPosts valueForKey:@"body"]objectAtIndex:i];
if (strTemp != nil)
{
jsonObjClass.body = [NSString stringWithFormat:@"%@",strTemp];
}
[jsonDataArray addObject:jsonObjClass];
[jsonObjClass release];
}
NSLog(@"Table View Reload....");
[self.tableView reloadData];
NSLog(@"Exit from connectionDidFinishLoading method");
}
In the above code i tried NSKeyedArchiver and NSkeyedUnarchiver for local storage but it not work and li'l complex so please give some example that i learn and implement easily. if is there any cache function then please send me...