Xcode 6 keeps renaming my app's directory in iOS8 simulator after each run.

Turns out Xcode 6 does in fact change the app's UUID every run, and I'm in the wrong for storing absolute paths.


USE SIMPHOLDERS

I used this app on Xcode 5 opens the Documents folder, for the currently running app in the simulator, in Finder.

http://simpholders.com/

not ready for Xcode 6 yet (as of sep 24 2014) but saves all this hassle.

In Xcode 6 / iOS8 The bundle is now separate from the data./ The application GUID is regenerated between runs in Xcode (not sure why)

  DOCUMENTS DIR:/Users/gbxc/Library/Developer/CoreSimulator/Devices/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Data/Application/C220D351-0BE7-46BA-B35E-D16646C61A3F/Documents
mainBundlePath_:/Users/gbxc/Library/Developer/CoreSimulator/Devices/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Bundle/Application/12200D1D-9B67-408B-BCF7-38206CBE0940/myappname.app/BLANK_BLOG_SCALED.jpg

1. FIND THE DEVICES FOLDER in SIMULATOR

/Users/gbxc/Library/Developer/CoreSimulator/Devices/

open each /device.plist to see which GUID is which device in XCode - I think this is static

3. FIND THE DEVICE you're running on iPad 2 - I think this is static

/Devices/AC79941F-EC56-495E-A077-773EEE882732

4. Find your application /Documents folder

/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Data/Application/C220D351-0BE7-46BA-B35E-D16646C61A3F/Documents

BEWARE the GUID C220D351-0BE7-46BA-B35E-D16646C61A3F is regenerated everytime the app is run in XCode 6

 NSArray *paths_ = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        if(paths_){
            _docsDir = [paths_ firstObject];
            DebugLog(@"DOCUMENTS DIR:%@",_docsDir);         
        }else{
            ErrorLog(@"paths_ is nil - cant get Documents directory");
        }

MAIN BUNDLE path

NSString *mainBundlePath_ = [[NSBundle mainBundle] pathForResource:@"someimageinyourbundle" ofType:@"jpg"];
/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Bundle/Application/12200D1D-9B67-408B-BCF7-38206CBE0940/clarksonsiq.app/BLANK_BLOG_SCALED.jpg

NEVER CACHE THE PATH to /Documents between runs it will change.

I was serializing it to a plist and couldnt figure out why they kept disappearing

The GUID above /Documents keeps changing between runs but if you have /Documents open in Finder the folder stays open.

https://devforums.apple.com/thread/235911?tstart=0

https://devforums.apple.com/thread/238754?tstart=0

Free Solution

Use Open Source Library OpenSim. OpenSim is an open source alternative for SimPholders, written in Swift.

Paid Solution

Use SimPholder application to know current application location.

enter image description here

For xcode 6.0 >

Download SimPholder 2.0 alpha 2


For xcode 5.1 <

Download SimPholders 1.5


I can confirm that this is Xcode 6 related not iOS 8.

I have two development machines. On one of them I have Xcode 5. I was working all the time on that machine and my URL's were fine (photo app, photos are visible).

Yesterday I checked in form git my source on a machine with Xcode 6. I noticed that my photos are not visible any more, only photos that are created during that app session.

After little debugging, I realized that file:///var/mobile/Applications/B6A6BAEF-C90C-4A2A-93DB-E6700B88971F/Documents/ is changing on every app run.

All that time I am working with iOS 7 device.

I am going to check once more on a machine with Xcode 5 to confirm when I get my hands on it.


You need to to save only path inside DocumentDirectory(directory/file name), and add it to the DocumentDirectory every time you load the file...

-(void)saveImage:(UIImage *)image{
NSData *pngData = UIImagePNGRepresentation(image);
NSString *pathInDocumentDirectory = [APP_DocumentDirectory stringByAppendingPathComponent:PROFILE_IMAGE_NAME];
NSString *filePath = [self documentsPathForFileName:pathInDocumentDirectory];
//Save pic file path - DirName/Filename.png
[XYZPreferencesHelper setUserImageFilePath:pathInDocumentDirectory];
 //Write the file
[[NSFileManager defaultManager] createFileAtPath:filePath contents:pngData attributes:nil];

}



-(void)loadSavedUserPicture{
//Load saved DirName/Filename.png
NSString *pathInDocumentDirectory = [XYZPreferencesHelper getUserImageFilePath];

if (pathInDocumentDirectory != nil){
    //Full path with new app Document Directory
    NSString *filePath = [self documentsPathForFileName:pathInDocumentDirectory];
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
        NSData *pngData = [NSData dataWithContentsOfFile:filePath];
        UIImage *image = [UIImage imageWithData:pngData];
        if (image != nil){
            userPicImageView.image = image;
        }

    }

 }
}



- (NSString *)documentsPathForFileName:(NSString *)name
{
NSString *documentsPath = [self createRestcallDirectoryIfNotExist];
return [documentsPath stringByAppendingPathComponent:name];
}



-(NSString *)createRestcallDirectoryIfNotExist{
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
path = [documentsPath stringByAppendingPathComponent:APP_DocumentDirectory];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:path])    //Does directory already exist?
{
    if (![[NSFileManager defaultManager] createDirectoryAtPath:path
                                   withIntermediateDirectories:NO
                                                    attributes:nil
                                                         error:&error])
    {
        NSLog(@"Create directory error: %@", error);
    }
}
return documentsPath;
}