我不再手動管理框架,而是使用和recommendCocoaPods來代替。
原來的答覆:
- 使用fake framework @提到wattson12。它也會編譯和保存資源。
通過this script的啓發,將它添加到你的目標的資源複製到你的應用程序:
SOURCE_PATH="${TARGET_BUILD_DIR}/MYFramework.framework/Resources/"
TARGET_PATH="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/MYFrameworkResources.bundle"
mkdir -p $TARGET_PATH
cp -R $SOURCE_PATH $TARGET_PATH
你也可以只拖動框架將複製的資源一步,但隨後你會添加不必要的標題和編譯代碼。
編輯
要使用從IB這些資源,例如png文件,替換:
MyImage
由:
MYFrameworkResources.bundle/MyImage.png
它將預覽殘缺的圖像圖標,但將在運行時起作用。
負荷碼筆尖:
[NSBundle loadNibNamed:@"MYFrameworkResources.bundle/MyNib" ...
最後,你可以在一個NSBundle類添加這些方法來緩解訪問筆尖資源,我在你的主束或MYFrameworkResources.bundle:
@implementation NSBundle (MyCategory)
+ (NSString *)pathForResource:(NSString *)name
ofType:(NSString *)extension
{
// First try with the main bundle
NSBundle * mainBundle = [NSBundle mainBundle];
NSString * path = [mainBundle pathForResource:name
ofType:extension];
if (path)
{
return path;
}
// Otherwise try with other bundles
NSBundle * bundle;
for (NSString * bundlePath in [mainBundle pathsForResourcesOfType:@"bundle"
inDirectory:nil])
{
bundle = [NSBundle bundleWithPath:bundlePath];
path = [bundle pathForResource:name
ofType:extension];
if (path)
{
return path;
}
}
NSLog(@"No path found for: %@ (.%@)", name, extension);
return nil;
}
+ (NSArray *)loadNibNamed:(NSString *)name
owner:(id)owner
options:(NSDictionary *)options
{
// First try with the main bundle
NSBundle * mainBundle = [NSBundle mainBundle];
if ([mainBundle pathForResource:name
ofType:@"nib"])
{
NSLog(@"Loaded Nib named: '%@' from mainBundle", name);
return [mainBundle loadNibNamed:name
owner:owner
options:options];
}
// Otherwise try with other bundles
NSBundle * bundle;
for (NSString * bundlePath in [mainBundle pathsForResourcesOfType:@"bundle"
inDirectory:nil])
{
bundle = [NSBundle bundleWithPath:bundlePath];
if ([bundle pathForResource:name
ofType:@"nib"])
{
NSLog(@"Loaded Nib named: '%@' from bundle: '%@' ", name, bundle.bundleIdentifier);
return [bundle loadNibNamed:name
owner:owner
options:options];
}
}
NSLog(@"Couldn't load Nib named: %@", name);
return nil;
}
@end
它會先看看你的應用程序包,然後在MYFrameworkResources.bundle等
嗨安德烈,你能告訴我你怎麼加的.bundle文件到框架目錄...我我無法做到這一點。我的shell腳本中可能有一些錯誤。 – Apple