我有一個OS X應用程序,我想在其中創建一些可交換的字符串和資源。 我創建了一個包skin.bundle
,我可以很容易地從它加載資源,如果我把束引入主要的應用程序包(這樣它就總是會下的.app /目錄放到/資源),並使用此代碼從PlugIns文件夾中加載資源包
NSString *path = [[NSBundle mainBundle] pathForResource:@"skin" ofType:@"bundle"];
if (path != nil) {
self.skinBundle = [NSBundle bundleWithPath:path];
[self.skinBundle load];
}
Cocoa bundle documentation使用PlugIns(.app/Contents/PlugIns我相信?)文件夾爲模塊化應用程序進行了討論,所以我試圖通過略微改變上述內容來做到這一點。
NSString *plugins = [[NSBundle mainBundle] builtInPlugInsPath];
NSString *path = [[NSBundle mainBundle] pathForResource:@"skin" ofType:@"bundle" inDirectory:plugins];
但是現在path
是零。我也試過[[NSBundle mainBundle] pathForResource:@"skin" ofType:@"bundle" inDirectory:@"PlugIns"]
,結果相同。
該軟件包包含一個有效的Info.plist文件(用於代碼簽名)。
我可以用第一種方法生活,但我當然很好奇。想想看,最好在Application Support文件夾中查找skin.bundle,以便輕鬆地繼續升級。