Search code examples
cocoa-touchiosadhoc

Ad hoc build changes documents directory


I've come up against a confusing issue. I'm using Testflight for ad hoc distribution to test my build with a few testers. My app makes use of the documents directory to store images taken with the camera or from the photo library.

The problem I have is that every time I install an ad hoc build from Testflight, it changes the app id part of the documents directory.

ie

/var/mobile/Applications/{APPID}/Documents/

is different after installing a new ad hoc build. It also changes if I reinstall the same build from Testflight. It was my understanding that this should be consistent - is this not correct?


Solution

  • The developer does not have control over what appid is used when the app is installed, so you should never trust it to be consistent. Instead ask the default file manager for the document directory on the fly:

    NSURL *documentDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];