Question

I have an app which displays text data with images and or videos which is displayed in a UITableView. I have a requirement now that the data must be available offline. I am thinking of pruge and store data every time I have a connection i.e new data is being downloaded. How can this be achieved - storing the data in a mysql table or any other solution. Please note that I am using AFNetworking to stream the images in uiimageview. The images and videos should be stored as blob is the local mysql database? Please note that my project is not using coredata.

Was it helpful?

Solution

The best way would probably be to download and store the media files in the caches directory.

Then, when you need to access a file, you can check to see if it exists, and if so, use it, and if not, handle that condition in whatever manner you need.

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
if(![fileManager fileExistsAtPath:[cachePath stringByAppendingPathComponent:@"myfile.zip"]]) {
    //create it, copy it from app bundle, download it etc.
}
//start using it

The caches directory is not backed up with the rest of your app, so if you have large files you will not impact the user's backup storage sizes this way.

If you absolutely must have the files in the backup, use the Documents directory instead of the caches directory.

You said you were using AFNetworking, which can stream a download to a file just fine, and even has support for turning the task into a background operation so that it can finish after the app has been closed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top