我不再手动管理框架,而是使用和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