gpt4 book ai didi

ios - bundleForClass 不返回框架包 iOS

转载 作者:行者123 更新时间:2023-11-29 00:06:44 26 4
gpt4 key购买 nike

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

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

NSString *readtext = [bundle **pathForResource**:@"Test" ofType:@"rtf"];

获取应用程序的appbundle(我使用框架的地方)而不是框架包。

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

最佳答案

您可以使用框架的 Bundle Identifier 加载 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"]];

关于ios - bundleForClass 不返回框架包 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47807753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com