Best way to store images in iOS - iphone

I was wondering if anyone could suggest the best way for me to store images for my app.
I want to be able to provide an XML update functionality that will allow the user to update their app with a new set of images. I was wondering what the best way to do this was as i need to read and write to the store location. Is storing them in a sqlite database the best way or am i able to use the filesystem to do this without the chance of the iPhone deleting any of the downloaded images?
Thanks

You can write to the filesystem, every app in iOS is sandboxed and has access to his own documents folder.
I would suggest to write on filesystem and only save the urls on the database as that is more performant than saving blobs on a database.
Apple has a good write up about the iOS filesystem.

Alternatively you could implement a solution using SQLite, Apple mentions it in the: Large Data Objects (BLOBs) section here:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html#//apple_ref/doc/uid/TP40003468-SW5

Related

What is the best approch to save images and xml file in device (sqliteDB)

I am creating an iPhone application in which i have to store images and xml files locally in device (sqliteDB). So my question is what is the best way to do this?
I have two approaches in my mind.
1) Store images and xml in device and just save references of them in to sqliteDB.
2) Encode images and xml file to Base64 and save to sqliteDB directly.
Which will be more wise and why?
Do anyone have any other way to perform this by which application can run smoothly.
you can store both xml and images in (sqllite) i think it is best because we can perform CRUD operations .
Saving and retrieving images to and from SQLite in iOS
you can find how to save images in sqllite
http://mobile.tutsplus.com/tutorials/iphone/iphone-sdk_store-data/
above tutorial is about how to use sqllite in ios and save data in sqllite ,saving all these
data in sqllite is a wise way to manage the resources ..

Storing .png images in an ios app?

Im creating an iphone game that will use more than 1200 .png image files, and all the images combined together come up to the size 11mb, i was wondering whats the best way to store them, i was going to use the s3 storage by amazon, but I would love them to be apart of the app in the resources folder, so users can play offline aswell. So i wanted get any opinions in what is the best way to store images in terms of caching and optimizating .png files in use with IOS Apps. thanks
Just drag them into xcode. 11 MB is not much, apple has raised their download limit over 3G/Edge.
Once you have them inside your project, you just call them like
UIImage *myImage1 = [UIImage imageNamed:#"1.png"];
It doesn't get simpler.
If you don't put the files inside your project and have to download them, you download these into your Documents folder. You can put what ever you want in that directory, as it is only for your project and no other project has access to it
11MB isn't much these days, your app can be upto 50MB and still be available to download over cellular networks so the best solution is;
a) Don't worry about it. Put them in your resources folder.
If you are going to have lots more images, then the easiest solution is to simply download them when the app has a network connection. You can store them in the Documents folder and mark them as do not backup so that they aren't synchronised with iCloud. You could also store them in the Caches folder, but that makes them much more liable to vanish at any moment so you would need to have a slightly more complex mechanism to recognise they are no longer on disk and to pull them in afresh.

How can I save images to iphone directory and retrieve it?

I want to save image in iphone album and retrieve them on particular index, how can I?
I have to save profile of many people, along with their images, so how can I access such concept?
Do not save images in iPhone album if they're your application related only.
The better way is to create directory in your application documents directory and store them there. Or even better, do use CoreData and transient property to store image on your disk to keep your data well organized.
you also have choice to save the image in sqlite3 database and retrieve it when needed.

getting data from server and store in the iPhone

i want to develop an iPhone app where the app downloads data (say audio clips) from a specified server and stores it locally on the device.
then the app should use the data stored in the device rather than stream it from the server.
could anybody give me the guidelines as to how this can be done? tutorials and samples also appreciated. Thanks :)
The easiest way to play files from the internet is to use -[AVAudioPlayer initWithContentsOfURL:error:]. If you want to make sure that the whole file is downloaded, I think your best bet would be to download the file using NSURLConnection (see the URL Loading Guide) and then using -[AVAudioPlayer initWithData:error:].
Look into ASIHTTPRequest, you will find it much easier to fetch large chunks of binary over the web asynchronously than if you try to code everything yourself.

Is there any way to save an image an default.png programmatically on the iphone?

I writing an app for the iphone and I would like to save an image from it as the default.png for the next invocation. Is this possible? It seems as if the sandbox doesn't allow you to overwrite anything in its local filesystem.
No, you can't. It used to be possible to make Default.png a symbolic link into your Documents folder, then to rewrite the location it pointed to, but functionality was removed in 3.0. You should file a bug with Apple explaining your needs.
No you cant, what you can do is save the image data to a file or using core data and then retrieve it for use.
So you can do something like
if(dataIsThere)
//use that data for image
else
use the default