首页 文章

每次运行后,Xcode 6会继续在iOS8模拟器中重命名我的应用程序目录 .

提问于
浏览
67

我正在运行Xcode 6 Beta 5,但自第一次测试以来,这种情况一直在发生 . 模拟器中的应用程序目录在每次运行后都会被重命名 . 我花了一段时间来弄明白这一点 . 我正在使用它来获取doc的dir参考 .

NSString *folder = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                        NSUserDomainMask,
                                                        YES) lastObject];

NSLog(@"Documents Dir: %@",folder);

现在例如在第一次运行时它将是:

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

现在第二次运行:

/ 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 / EC8F41E8-52ED-4B10-9808-B3ACC46FC6AA / Documents

这对我的应用程序造成了严重破坏,因为它存储了应用程序中某些文件的路径引用 . 这不是我的NSLog语句返回不正确的结果,我验证了这是在Finder中发生的事情 . 它每次都在改变这个名字 . 有没有人见过这种情况?这是一个我误解的“特征”吗?

5 回答

  • 7

    事实证明Xcode 6实际上每次运行都会更改应用程序的UUID,而我存储绝对路径的错误 .

  • 49

    USE SIMPHOLDERS

    我在Xcode 5上使用这个应用程序,在Finder中为模拟器中当前运行的应用程序打开Documents文件夹 .

    http://simpholders.com/

    还没有为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)

    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/
    

    打开每个/device.plist以查看哪个GUID是XCode中的哪个设备 - 我认为这是静态的

    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
    

    请注意GUID C220D351-0BE7-46BA-B35E-D16646C61A3F每次在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.

    我把它连载到一个plist并且无法弄清楚它们为什么一直在消失

    上面的/ GUID在运行之间不断变化但是如果在Finder中打开/ Documents文件夹保持打开状态 .

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

    Free Solution

    使用开源库OpenSim . OpenSim是SimPholders的开源替代品,用Swift编写 .

    Paid Solution

    使用SimPholder应用程序了解当前的应用程序位置 .

    enter image description here

    对于xcode 6.0>

    下载SimPholder 2.0 alpha 2


    对于xcode 5.1 <

    下载SimPholders 1.5

  • 1

    我可以确认这是Xcode 6与iOS 8无关 .

    我有两台开发机器 . 在其中一个我有Xcode 5.我一直在那台机器上工作,我的网址很好(照片应用程序,照片可见) .

    昨天我在带有Xcode 6的机器上检查了git我的源代码 . 我注意到我的照片不再可见,只有在该应用程序会话期间创建的照片 .

    经过一些调试,我意识到文件:/// var / mobile / Applications / B6A6BAEF-C90C-4A2A-93DB-E6700B88971F / Documents /正在改变每个应用程序运行 .

    我一直在使用iOS 7设备 .

    我将再次在带有Xcode 5的机器上进行检查,以确认我什么时候拿到它 .

  • 1

    您需要在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;
    }
    

相关问题