views:

216

answers:

2

I display text and images in a UIWebView. Content isn't always the same. I access images within the content using the bundle path. For an inbetween versions update of content, I'd like to allows users the ability to download new content (text & images). This new content will also display in a UIWebView. The problem is I will have to use a disk path rather than my common pattern of using the bundle path. Unless there is a way to repackage the image at runtime into the bundle.

Once the next app store update for the app is availble, all of the previously downloaded images will be in the app bundle. On this update, I'll write overwrite the previous content and use the bundle path for images. Content will be exactly the same minus the image path.

Can anyone give some insight into how this might work or a better approach?

+5  A: 

So far as I know you cannot repackage the bundles on the iPhone once your app has been released to the App Store. So go the other way, and put the data from the bundle on the filesystem so you can change it at runtime.

My usual technique for this stuff is:

  • bundle up the initial data
  • have a routine that checks for the presence of a versioned file on the iPhone's filesystem at startup
  • if that routine doesn't find the current version of the file, copy all the data into the iPhone's filesystem
  • reference the data from the filesystem in my app, rather than using the bundle path

So, essentially your bundle is just a delivery mechanism, a way to preload the filesystem with the stuff you are going to need. Once it's on the filesystem you can change anything you wish.

Benjamin Cox
+1  A: 

Agree with Benjamin - you cannot change your bundle contents.
Instead you can (and should) save your downloaded contents to Documents folder of your application sandbox. You can get the path to it this way:

// Look in Documents for an existing plist file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

Moreover contents of this folder persists during updates so it may be not necessary to put downloadable optional contents to the application bundle.

Vladimir
Thanks. The problem is I already have lots of content referencing images in the app bundle. Going forward, only the small number of updates will reference images on disk. I can't deploy all of the images in say version 1.2 for saving space b/c people getting version 1.3 will then need to download all of those images.
4thSpace
I'm a little confused by that last sentence. Wouldn't the images from 1.3 replace the images from 1.2? Or are you talking about saving space on the app download, itself?
Benjamin Cox
Yes - it was in regards to downloading. For new users, the images will always need to be in the app bundle. Otherwise, they will have fragmented content.
4thSpace