Reputation: 170
I have to build an iPhone app that check for the net connectivity and whenever it get it has an online sync with a web service, it downloads X images and saves them into the device.
Then, in offline mode, I have to load the images in collectionview for that i have to store images somewhere.Same For data also
I am using .net webservice with json response.
I was thinking about the Core Data storage, is that possible? Maybe storing images in core data database will slow down the app?
Upvotes: 1
Views: 1704
Reputation: 375
Yes you can store images in core data in the form of Binary Data, here is an example of how to do it link! As far as speed is concerned core data will not slow down your app performance but it usually takes more space than sqlite, here's a link! that show comparison between core data and sqlite performance.
Upvotes: 0
Reputation: 194
Yes,it is possible,but not worthwhile.
As usually,we cache an image with follow steps:
step 2
,otherwise,go step 3
There is a tool can do bellow work well,you can try using SDWebImage.
Upvotes: 0
Reputation:
You have to download and save each received image in the application directory, then you save in CoreData the path to those images.
// Save image to disk
NSString *documentaryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/Image.png",documentaryPath];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(YOUR_IMAGE)];
[data writeToFile:filePath atomically:YES];
// Retrieve the Image
- (NSData *) imageData {
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/Image.png",docDir];
NSData *dataImage = [NSData dataWithContentsOfFile:pngFilePath];
return dataImage;
}
And use like below.
UIImage *image = [UIImage imageWithData:imageData]
May be it will help you.
Upvotes: 5