每次运行后,Xcode 6 都会在 iOS8 模拟器中重命名我的应用程序目录。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25233386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 6 keeps renaming my app's directory in iOS8 simulator after each run.
提问by Joseph Toronto
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.
我正在运行 Xcode 6 Beta 5,但这自第一个测试版以来一直在发生。每次运行后,我的应用程序在模拟器中的目录不断被重命名。我花了一段时间才弄清楚这一点。我正在使用它来获取文档的目录参考。
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
/用户/乔伊/库/开发商/ CoreSimulator /设备/ 5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE /数据/容器/数据/应用/ 4B10C2E4-A5C3-4C64-93B1-4069FCCB9C46/文件
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
/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
/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?
这对我的应用程序造成了严重破坏,因为它存储了应用程序中某些文件的路径引用。并不是我的 NSLog 语句返回了错误的结果,我验证了 Finder 中发生的情况。每次都改名字。有没有人看到这种情况发生?这是我误解的“功能”吗?
采纳答案by Joseph Toronto
Turns out Xcode 6 does in fact change the app's UUID every run, and I'm in the wrong for storing absolute paths.
事实证明,Xcode 6 实际上每次运行都会更改应用程序的 UUID,而我在存储绝对路径方面是错误的。
回答by brian.clear
USE SIMPHOLDERS
使用 SIMPOLDERS
I used this app on Xcode 5 opens the Documents folder, for the currently running app in the simulator, in Finder.
我在 Xcode 5 上使用了这个应用程序,在 Finder 中为模拟器中当前正在运行的应用程序打开了 Documents 文件夹。
not ready for Xcode 6 yet (as of sep 24 2014) but saves all this hassle.
尚未为 Xcode 6 做好准备(截至 2014 年 9 月 24 日),但省去了所有这些麻烦。
In Xcode 6 / iOS8 The bundle is now separate from the data./ The application GUID is regenerated between runs in Xcode (not sure why)
在 Xcode 6 / iOS8 中,捆绑包现在与数据分开。/ 应用程序 GUID 在 Xcode 中的运行之间重新生成(不知道为什么)
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
1. 在模拟器中找到设备文件夹
/Users/gbxc/Library/Developer/CoreSimulator/Devices/
open each /device.plist to see which GUID is which device in XCode - I think this is static
打开每个 /device.plist 以查看哪个 GUID 是 XCode 中的哪个设备 - 我认为这是静态的
3. FIND THE DEVICE you're running on iPad 2 - I think this is static
3. 找到您在 iPad 2 上运行的设备 - 我认为这是静态的
/Devices/AC79941F-EC56-495E-A077-773EEE882732
4. Find your application /Documents folder
4. 找到您的应用程序 /Documents 文件夹
/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
请注意,每次在 XCode 6 中运行应用程序时都会重新生成 GUID C220D351-0BE7-46BA-B35E-D16646C61A3F
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.
永远不要在运行之间缓存到 /Documents 的路径,它会改变。
I was serializing it to a plist and couldnt figure out why they kept disappearing
我正在将它序列化到 plist 中,但无法弄清楚它们为什么不断消失
The GUID above /Documents keeps changing between runs but if you have /Documents open in Finder the folder stays open.
/Documents 上方的 GUID 在运行之间不断变化,但如果您在 Finder 中打开了 /Documents,则该文件夹将保持打开状态。
https://devforums.apple.com/thread/235911?tstart=0
https://devforums.apple.com/thread/238754?tstart=0
回答by Paresh Navadiya
Free Solution
免费解决方案
Use Open Source Library OpenSim. OpenSim is an open source alternative for SimPholders, written in Swift.
使用开源库OpenSim。OpenSim 是 SimPholders 的开源替代品,用 Swift 编写。
Paid Solution
付费解决方案
Use SimPholder application to know current application location.
使用 SimPholder 应用程序了解当前应用程序位置。
For xcode 6.0 >
对于 xcode 6.0 >
Download SimPholder 2.0 alpha 2
下载SimPholder 2.0 alpha 2
For xcode 5.1 <
对于 xcode 5.1 <
Download SimPholders 1.5
下载SimPholders 1.5
回答by vale4674
I can confirm that this is Xcode 6 related not iOS 8.
我可以确认这是 Xcode 6 相关而不是 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).
我有两台开发机器。其中一个我有 Xcode 5。我一直在那台机器上工作,我的 URL 很好(照片应用程序,照片可见)。
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.
昨天,我在装有 Xcode 6 的机器上检查了表单 git my source。我注意到我的照片不再可见,只有在该应用程序会话期间创建的照片。
After little debugging, I realized that file:///var/mobile/Applications/B6A6BAEF-C90C-4A2A-93DB-E6700B88971F/Documents/ is changing on every app run.
经过一些调试,我意识到 file:///var/mobile/Applications/ B6A6BAEF-C90C-4A2A-93DB-E6700B88971F/Documents/ 在每次应用程序运行时都会发生变化。
All that time I am working with iOS 7 device.
一直以来我都在使用 iOS 7 设备。
I am going to check once more on a machine with Xcode 5 to confirm when I get my hands on it.
我将在装有 Xcode 5 的机器上再次检查以确认我何时可以使用它。
回答by Shlomi Fresko
You need to to save only path inside DocumentDirectory(directory/file name), and add it to the DocumentDirectory every time you load the file...
您只需要在 DocumentDirectory(目录/文件名)中保存路径,并在每次加载文件时将其添加到 DocumentDirectory...
-(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;
}