Lion下的NSUserDefaults和沙箱 [英] NSUserDefaults and sandboxing under Lion

查看:95
本文介绍了Lion下的NSUserDefaults和沙箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Apple的要求,移动我的一个项目来支持沙箱.我像这样使用UserDefaults:

Moving one of my projects to support sandboxing as per Apple's requirements. I use UserDefaults like so:

[[NSUserDefaults standardUserDefaults] setObject:@(myNumber) forKey:myNumberKey];
[[NSUserDefaults standardUserDefaults] synchronize];

一切正常,直到启用沙箱功能为止.如果启用了沙箱功能,则应用程序会在沙箱目录(.plist.lockfile)中创建一个锁定文件,而不创建实际的.plist文件.

Everything works as expected until I enable sandboxing. If I have sandboxing enabled the app creates a lock file in it's sandbox directory ( .plist.lockfile) and doesn't create an actual .plist file.

我在做错什么,如何在沙盒环境下将设置存储在UserDefaults中?

What am I doing wrong and how do I store my settings in UserDefaults under sandbox environment?

更新:在单独的Mac上使用最新的Xcode安装了最新的10.7.3-同一项目可以编译并在启用沙箱的情况下正常运行.

Update: Installed fresh 10.7.3 with the latest Xcode on a separate Mac - the same project compiles and works fine with sandboxing enabled.

我还尝试在Mac上运行该项目,其中沙箱无法在具有完全相同结果的其他用户帐户(新创建)下运行,无法进行.在这一点上,我认为问题在于此特定Mac上的系统配置.但问题是-可以肯定地说我是这个奇怪问题中唯一的一个吗?可能不是...

Also I've tried to run this project on my Mac where the sandbox doesn't work under different user account (freshly created) with exactly the same results - no go. At this point I think the problem is with system configuration on this particular mac. Question is though - is it safe to assume that I'm the only one with this weird problem? Probably not...

推荐答案

应该可以.如果首选项系统能够创建锁定文件,则意味着您的应用程序具有在该目录中创建文件的适当特权,并且已正确查找了应将文件放置在何处的位置.因此,肯定有其他地方出问题了.

That should work fine. If the preferences system is able to create the lock file, that means your app has appropriate privileges to create files in that directory and has correctly looked up the location where it should put them. Therefore, something else must be going wrong.

发生这种情况时是否有任何控制台日志记录? -synchronize的返回值是什么?

Is there any Console logging when this occurs? What's the return value of -synchronize?

(顺便说一句:通常,不需要-synchronize只会使您的应用变慢,NSUserDefaults会自行处理)

(aside: in general -synchronize is not necessary and will just make your app slower, NSUserDefaults will handle that itself)

这篇关于Lion下的NSUserDefaults和沙箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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