offline json access

Joined
Jun 3, 2013
Messages
1
Reaction score
0
Points
1
Hi
in my app, need to download the json data for the 1st time when the user install the app , then for the 2nd time need to reuse the downloaded data even witout internet connection also. for that i have used "NSUserdefault" but i couldnt access the data in offline.. please help me to sort out this issue.. im really fed up... this is my code:

//load json

-(void)viewDidAppear : (BOOL)animated
{

_feed = [[data alloc] initFromURLWithString : @"http://www.fr6.wearedesigners.net/WAD/index.php/wad/getProject"
completion:^(JSONModel *model, JSONModelError *err) {


//json fetched
NSLog(@"Projects: %@", _feed.Projects);

//reload the table view
[self.collectionView reloadData];
}];
}


-(NSInteger)collectionView : (UICollectionView *)collectionView numberOfItemsInSection : (NSInteger)section
{
return _feed . Projects . count;
}

-(UICollectionViewCell *)collectionView : (UICollectionView *)collectionView
cellForItemAtIndexPath : (NSIndexPath *)indexPath
{

NSUserDefaults *saved=[NSUserDefaults standardUserDefaults];

model* bankIcons=_feed . Projects[indexPath . row];

[saved setObject : bankIcons . logo forKey : @"_feed"];

[saved synchronize] ;

NSString *savedval=[[NSUserDefaults standardUserDefaults]stringForKey : @"_feed"];


custom *cell = [collectionView
dequeueReusableCellWithReuseIdentifier : @"Cell"
forIndexPath : indexPath];

UIImage *image = [UIImage imageWithData : [NSData dataWithContentsOfURL : [NSURL URLWithString:savedval]]] ;
cell.displayImage.image = image ;

return cell ;

}
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top