【发布时间】:2014-10-19 04:11:09
【问题描述】:
为了在我的应用程序和扩展程序之间共享代码和资源,我在我的项目中嵌入了一个Cocoa Touch Framework,这个框架包含一些资源,如图像和 xib 文件。
我的问题是:我如何从可能的主应用程序和扩展程序访问这些资源?
我以前用这个方法:iOS 8 Extension: how to use xib inside Cocoa Touch Framework in extensions?
但这会复制到应用程序包和扩展程序包中的所有资源,这不是一个好的重复。
有没有更好的办法?
更新:
现在我的主应用程序可以使用这样的代码来访问框架中的资源:
+(NSBundle*)frameworkBundle
{
NSString *frameworkDirPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *frameworkBundlePath = [frameworkDirPath stringByAppendingPathComponent:@"MyFramework.framework"];
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
return frameworkBundle;
}
但这不适用于扩展。
【问题讨论】:
标签: ios cocoa-touch ios8