4thSpace
4thSpace

Reputation: 44312

Downloading image into bundle?

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?

Upvotes: 0

Views: 1720

Answers (2)

Vladimir
Vladimir

Reputation: 170839

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.

Upvotes: 1

Benjamin Cox
Benjamin Cox

Reputation: 6120

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.

Upvotes: 5

Related Questions