Car*_*loS 5 cocoa-touch ios ios8
为了在我的应用程序和扩展程序之间共享代码和资源,我Cocoa Touch Framework在我的项目中嵌入了一个,该框架包含一些资源,如image和xib文件.
我的问题是:如何从主应用程序和扩展程序中访问这些资源?
我曾经使用过这种方法:iOS 8扩展:如何在Cocoa Touch Framework中使用xib扩展?
但这将复制到应用程序包和扩展程序包中的所有资源,这不是一个好的重复.
有没有更好的办法?
更新:
现在我的主应用程序可以使用这样的代码来访问框架中的资源:
+(NSBundle*)frameworkBundle
{
NSString *frameworkDirPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *frameworkBundlePath = [frameworkDirPath stringByAppendingPathComponent:@"MyFramework.framework"];
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
return frameworkBundle;
}
Run Code Online (Sandbox Code Playgroud)
但这不适用于扩展.
Ton*_*ony 15
试试这个:
NSBundle *frameworkBundle = [NSBundle bundleForClass:[AnyClassFromFramework class]];
Run Code Online (Sandbox Code Playgroud)
小智 5
这对我有用:
NSBundle * frameworkBundle = [NSBundle bundleWithIdentifier:@"<framework-bundle-identifier>"];
Run Code Online (Sandbox Code Playgroud)