objective-c 删除 plist 文件不会在 macOS 10.9+ 上重置应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19303958/
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
Deleting plist file does not reset app on macOS 10.9+
提问by Bryan
While developing a Cocoa application on 10.9, I have noticed that if I go to ~/Library/Preferencesand delete the plist file for my app (to reset it), on the next build-and-run, the app behaves as if the plist file had never been deleted at all.
在 10.9 上开发 Cocoa 应用程序时,我注意到如果我去~/Library/Preferences删除我的应用程序的 plist 文件(重置它),在下一次构建和运行时,应用程序的行为就好像 plist 文件从来没有完全删除。
It took me a long time to track down why this happens and I did not see a question/answer about it on SO, so I'm writing this question and answering it myself to help others.
我花了很长时间来追查为什么会发生这种情况,但我没有在 SO 上看到有关它的问题/答案,所以我正在写这个问题并自己回答以帮助他人。
回答by Bryan
On 10.9, the system is doing some more robust "caching" of preferences. After deleting the plist file, I fired up Activity Monitor and force-killed the "cfprefsd" process. Be careful: there are multiple processes with this name running and you only want to kill the one running under your own user; do not kill the one running as root.
在 10.9 上,系统正在对偏好进行一些更强大的“缓存”。删除 plist 文件后,我启动了活动监视器并强制终止了“cfprefsd”进程。注意:有多个同名的进程在运行,你只想杀死在你自己的用户下运行的进程;不要杀死以 root 身份运行的那个。
Doing this seems to flush the preferences cache and on the next run of my app, I get a pristine start-from-scratch launch.
这样做似乎刷新了首选项缓存,并且在我的应用程序的下一次运行中,我得到了一个原始的从头开始的启动。
Edit: As reported below, using defaults delete [your bundle identifier]at the command line also appears to eliminate the caching issue. I've had mixed success with this.
编辑:如下所述,defaults delete [your bundle identifier]在命令行中使用似乎也可以消除缓存问题。我在这方面取得了喜忧参半的成功。
回答by Pencilcheck
I found out that killing the user process cfprefsd will reflush the cache, so your changes will be kept
我发现杀死用户进程 cfprefsd 将刷新缓存,因此您的更改将被保留
killall -u $USER cfprefsd
killall -u $USER cfprefsd
回答by Tom Andersen
In terminal:
在终端:
defaults delete com.somecompany.someapp
defaults delete com.somecompany.someapp
回答by Thomas Tempelmann
BTW, I've just released a GUI app that may be more convenient than working with the defaults command:
顺便说一句,我刚刚发布了一个 GUI 应用程序,它可能比使用 defaults 命令更方便:
http://www.tempel.org/PrefsEditor
http://www.tempel.org/PrefsEditor
It works practically the same as Xcode's plist editor, but affects the user's app preferences directly.
它的工作原理与 Xcode 的 plist 编辑器几乎相同,但直接影响用户的应用程序首选项。
To delete all your prefs, you could open your prefs in my Prefs Editor, Select All, then delete them with the Backspace or Delete key, and they're instantly all gone.
要删除所有首选项,您可以在我的首选项编辑器中打开您的首选项,全选,然后使用 Backspace 或 Delete 键删除它们,它们立即全部消失。
However, for this particular task, using defaults deletemight still be quicker, especially if you put the command into a text file ending in ".command", and make it executable (with chmod +x). Then you can double click it from the Finder to execute it.
但是,对于此特定任务,使用defaults delete可能仍然更快,尤其是如果您将命令放入以“.command”结尾的文本文件中,并使其可执行(使用chmod +x)。然后您可以从 Finder 中双击它以执行它。

