Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm running Xcode 6 Beta 5 but this has been happening since the first beta. My app's directory in the simulator keeps being renamed after each run. It took me a while to figure this out. I'm using this to get the doc's dir reference.

NSString *folder = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,                                                         NSUserDomainMask,                                                         YES) lastObject];  NSLog(@"Documents Dir: %@",folder); 

Now for example on the first run it'll be:

/Users/Joey/Library/Developer/CoreSimulator/Devices/5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE/data/Containers/Data/Application/4B10C2E4-A5C3-4C64-93B1-4069FCCB9C46/Documents

Second run now it's:

/Users/Joey/Library/Developer/CoreSimulator/Devices/5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE/data/Containers/Data/Application/7E9EB62D-115A-4092-AD23-CB6BA3E5E10F/Documents

Third run:

/Users/Joey/Library/Developer/CoreSimulator/Devices/5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE/data/Containers/Data/Application/EC8F41E8-52ED-4B10-9808-B3ACC46FC6AA/Documents

This is wreaking havoc with my app because it stores path references for certain files within the app. It's not that my NSLog statement is returning incorrect results, I verified this is what happening in Finder. It's changing the name every time. Has anyone seen this happen? Is this a "feature" that I'm misunderstanding?

like image 267
Joseph Toronto Avatar asked Aug 10 '14 21:08

Joseph Toronto


2 Answers

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

like image 117
Joseph Toronto Avatar answered Oct 04 '22 04:10

Joseph Toronto


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 
like image 23
brian.clear Avatar answered Oct 04 '22 05:10

brian.clear