如何在Mac OS X上阅读ANOTHER应用程序的plist文件?

时间:2014-10-03 18:17:58

标签: objective-c macos bundle plist

我正在为另一个应用程序创建一个插件,我想访问一个plist文件。

我尝试了以下操作,但无法找到该文件。

NSBundle* bundle = [[NSBundle mainBundle] initWithPath:@"~/Library/Containers/com.Apple.Externalapp/"];
NSString* filePath = [bundle pathForResource:@"container" ofType:@"plist"];

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
    NSLog(@"File exists");
} else {
    NSLog(@"File doesn't exist");
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您从[NSBundle mainBundle]开始。该方法返回应用程序的NSBundle,完全初始化。您向此初始化的捆绑包发送initWithPath消息;从那以后事情就会变得非常错误。

你可能想要[[NSBundle alloc] initWithPath... ]