Keep App directory the same when building for iPhone Simulator?

后端 未结 2 2032
情歌与酒
情歌与酒 2021-01-24 11:59

I\'m building an iPhone app, and my app copies a bunch of resources to the App\'s Documents directory on first install. While I\'m developing the app, I simply modify files in t

2条回答
  •  没有蜡笔的小新
    2021-01-24 12:40

    I never did find a way to do this using the app guid, but ultimately I did find a work around. All I did was put all my references to the applications installation directory into a function, and change that function so if I'm running in the simulator, it returns a hard coded directory on my system.... That way the directory would always stay the same even if I reinstall the app, so I can edit my files without losing them when I do a build.

    +(NSString *) appDocsDir
    {
    #if TARGET_IPHONE_SIMULATOR
    
            NSString* result = @"/Users/brad/ezappdir";
    #else
    
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                                                 NSUserDomainMask, 
                                                                 YES); 
            NSString* result = [paths objectAtIndex:0];
    #endif
    
        return result;
    }
    

提交回复
热议问题