0

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...

rmaddy
  • 307,833
  • 40
  • 508
  • 550
JAY RAPARKA
  • 1,323
  • 2
  • 13
  • 32
  • store them on local storage if you want to store small data check NSUserDefault – Saad Chaudhry May 01 '14 at 05:24
  • store them using core data. see this http://stackoverflow.com/questions/3353172/save-and-retrieve-of-an-uiimage-on-coredata – Shruti May 01 '14 at 05:26
  • @Shruti i can use but there is every time image conversion of image to data and my image coming form url so i don't know about the type of image and in conversion PNGRepresentation , JPGRepresentation etc.. so i have to check every time the type of imege that is PNG OR JPG OR JPEG – JAY RAPARKA May 01 '14 at 05:39

0 Answers0