2

I am working on a Vegetable gardening application. Apart from the vegetable name and description I also have vegetable image. Currently, I have all the images in the Supported Files folder in the Xcode project.

But later on I want to update the application dynamically without having the user download a new version. When the user updates the application or downloads new data from the server that data will include the images. Can I store those images in the supporting file folder or somewhere where they can be references by just the name.

RELATED QUESTION:

I will also allow the user to take pictures of their vegetables and then write notes about the vegetables like "just planted", "about to harvest" etc. What is the recommended approach for storing pictures/photos. I can always store them in the user's photo library and then store the reference in the local database and then fetch and display the picture using the reference. The problem with that approach might be that if the user accidentally deletes the picture from the library then it will no longer be displayed in my application.

The only way I see if to store the picture in the app local database as a BLOB.

azamsharp
  • 19,710
  • 36
  • 144
  • 222

1 Answers1

3

No you can't put the downloaded images with the others inside the supporting file folder. Also I would suggest you put the images inside an Images or Resources folder instead... If you want to download any data after the app is compiled, then they will not be in the bundle. It is the bundle you are referring to when talking about the Supported Files folder in Xcode. This is read only for your application.

Just to be clear, once compiled, there are no folder structures for your application, these "folders" are just groups in the Xcode project to keep things tidy.

If you download say a zip file containing a set of images, it's up to you to write them to disk after you download them. You should put these images in either the tmp, the cache or the documents directory.

But then you'll have to build your path before loading the images. You won't be able to just provide the name of the file such as:

[UIImage imageNamed:@"something.jpg"];

Because this will look in your bundle. Instead you must do something like this to load your image from the Documents directory for example.

Your challenge is that you will end up in a state where you'll have some images in the Bundle (the ones from when you uploaded your app), and the newer ones in the documents directory. You must them check the bundle first and if there is no image there, check the documents directory.


For user generated data, I suggest also saving the images in the Documents directory, and maintaining an SQLite database of the users data, so you can map an image name to an entry in the database. You don't want to save the images as BLOB because this will inevitably slow down the performance of your queries and add extra unnecessary load on the CPU to convert to UIImage and back.

You don't want to save their images to the gallery for 2 reasons, first this means you'll be saving in 2 places because keeping a reference in your database to an external image is very fragile and you're just asking for trouble, and secondly, once the image isn't under your wing, you don't control it anymore, the user will delete it at some point, if they go back to your app they expect to see it there.

Community
  • 1
  • 1
Daniel
  • 23,129
  • 12
  • 109
  • 154
  • No, once your app is compiled, all the images, files (header files) become what is called the Bundle. When your app is installed, you can read anything from the bundle, your app reads the different files to run, can load images for the UI etc. But at no point can you edit, add or delete from that Bundle. It's locked. Readonly. So if you need to "update" via downloading, you can download but you cannot save to the bundle. So you're forced to save in the sandbox, usually you'd use the Documents directory. The problem then is your code has to be prepared to load from somewhere outside the bundle. – Daniel Oct 15 '12 at 20:47
  • So what do you think is a better solution? I don't want to store everything on server since then it will be little slow and will require internet connection. I also don't want to provide small updates to the users which will just contain new vegetables. I want to update the content remotely. – azamsharp Oct 15 '12 at 21:25
  • Yes you should have your own server. I did this once with Channel 4's Fish Fight app. It bundled with recipes and fish guide. But when you launch the app is checks with a server for any new items. I send the date that I last got an update and the server works out from that date until now, what's new. I than got a JSON with (or not) content, for example an array of image URLs, then one by one download them and save to the Documents directory, updating my SQLite database as I go. When all is done, I change my "last updated" date to now and next launch that will be used for checking new content. – Daniel Oct 15 '12 at 21:28
  • I just added a related question in the original question. – azamsharp Oct 15 '12 at 21:29
  • 1
    Thanks a million for your help! Now back to programming my fun Vegetable app :) – azamsharp Oct 15 '12 at 21:34
  • I've been working on something very very similar :) I'll send you the link when it's in the App store – Daniel Oct 15 '12 at 21:36