为iPhone模拟器构建时,保持App目录相同吗? [英] Keep App directory the same when building for iPhone Simulator?

查看:113
本文介绍了为iPhone模拟器构建时,保持App目录相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个iPhone应用程序,我的应用程序会在首次安装时将一堆资源复制到App的Documents目录中。在我开发应用程序时,我只需修改App Sim's文档目录中的iPhone Simulator文件,以便在不重建应用程序的情况下轻松测试内容。

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 the App's Documents directory for the iPhone Simulator to make it easy to test out things without having to rebuild the app.

但是当我重建应用程序时,应用程序的GUID(在其安装目录名称中使用)会被更改,而我打开的所有文件现在都指向无效的目录。

But when I do rebuild the app, the App's GUID, which is used in it's installation directory name, is changed, and any files I had opened are now pointing at an invalid directory.

所以简而言之,在安装到iPhone模拟器时,是否还要强制App的GUID保持不变?这将允许我编辑VIM中的文件,而不是让我们在构建时消失。我已经搜索了StackOverflow的答案,并且没有看到任何....最接近的是:

So in short, is there anyway to force the App's GUID to be constant when installing to the iPhone simulator? This would allow me to edit files in VIM and not have them "disappear' when I do a build. I've searched StackOverflow for an answer, and haven't seen any.... The closest was this:

如何保持iphone模拟器应用程序目录在每次运行时保持不变

但它不是同样的问题!

谢谢!

推荐答案

我从未找到过使用app guid做到这一点的方法,但最终我确实找到了解决办法。我所做的就是把我对应用程序安装目录的所有引用都放到一个函数中,并改变那个函数,这样如果我在模拟器中运行它,返回我的系统上的硬编码目录....这样,即使我重新安装应用程序,目录也将始终保持不变,因此我可以编辑我的文件而不会丢失它们我做了一个构建。

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;
}

这篇关于为iPhone模拟器构建时,保持App目录相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆