【发布时间】:2011-02-02 13:57:59
【问题描述】:
我正在尝试通过读取 plist 来设置图像。我正在开发一个使用当前桌面壁纸并将其设置为 Windows 背景图像的应用程序。文件位于~/Library/Preferences/com.apple.desktop.plist
我如何从中读取密钥?我正在尝试读取的特定键是;
NewImageFilePath
ImageFilePath
我已经尝试过这段代码,就像在 iPhone 上阅读 plist 一样,但它没有用。
NSString *plistPath = @"~/Library/Preferences/com.apple.desktop.plist";
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:plistPath] retain];
NSString *item = [plistData objectForKey:@"NewImageFilePath"];
NSLog([NSString stringWithFormat:@"%@", item]);
一旦我可以获取位于 plists 字符串中的实际数据,我的计划是将其设置为 NSImageView 或 [window setBackgroundColor:[color]]; 方法
提前致谢。
【问题讨论】:
-
您保留那本词典有什么原因吗?此外,您应该重命名该变量,因为它包含字典,而不是数据。