bundleForClass不返回框架包iOS

bundleForClass不返回框架包iOS,ios,objective-c,nsbundle,Ios,Objective C,Nsbundle,使用bundleForClass检索我定义了类的框架包 NSBundle *bundle = [NSBundle **bundleForClass**: [self class]]; // Class in framework NSString *readtext = [bundle **pathForResource**:@"Test" ofType:@"rtf"]; 获取应用程序的appbundle(我正在使用我的框架),而不是框架bundle 如何获取框架捆绑包路径并读取框架资源。您可

使用bundleForClass检索我定义了类的框架包

NSBundle *bundle = [NSBundle **bundleForClass**: [self class]]; // Class in framework

NSString *readtext = [bundle **pathForResource**:@"Test" ofType:@"rtf"];
获取应用程序的appbundle(我正在使用我的框架),而不是框架bundle


如何获取框架捆绑包路径并读取框架资源。

您可以使用框架的捆绑包标识符加载NSBundle:

[NSBundle bundleWithIdentifier:YOUR_FRAMEWORK_BUNDLE_IDENTIFIRE];
如果框架中包含资源包,则可以通过以下方式访问资源:

NSBundle *bundle = [NSBundle bundleForClass:[YOUR_CLASS_NAME class]];
NSURL *url = [bundle URLForResource:RESOURCE_BUNDLE_NAME withExtension:@"bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithURL:url];
UIImage* infoImage = [UIImage imageWithContentsOfFile:[resourceBundle pathForResource:@"info" ofType:@"png"]];

根据苹果的NSBundle返回值文档——动态加载aClass(可加载的捆绑包)的NSBundle对象,定义aClass的框架的NSBundle对象,如果未动态加载aClass或未在框架中定义aClass,则为主捆绑包对象。我们可以在框架资源中动态编辑txt文件吗?您不能编辑该文件,但可以复制到此文件的文档目录,并可以对其进行更改。