在我使用 podspec 加载资源之前:
s.resources = ["MyFramework/Resources/**/*.{xib, png, jpeg, jpg}"]
现在我尝试用以下方法完成同样的事情:
s.resource_bundles = {'Resources' => ['MyFramework/Resources/**/*.{xib, png, jpeg, jpg}']}
它们似乎是复制的,因为我可以在以下位置找到它们:
Pods\Development Pods\MyFramework\Resources
但是当我尝试加载它们时:
UIImage *testImage = [UIImage imageNamed:@"testImage.jpeg"];
testImage
始终为 nil。
我还试图找出是否可以通过某种方式访问 bundle ,因此我需要从创建的 bundle 中加载图像,但是:
NSArray *bundles = [[NSBundle mainBundle] pathsForResourcesOfType:@"bundle" inDirectory:nil];
显示没有通过 Cocoapods 创建包。
我究竟如何访问这些资源?
最佳答案
资源放在一个名为“资源”的包中。
s.resource_bundles = {'Resources' => ['MyFramework/Resources/**/*.{xib, png, jpeg, jpg}']}
您可以通过以下代码访问包
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle]
pathForResource:@"Resources"
ofType:@"bundle"]];
s.resource_bundles
中的键是包名称。
注意: 我有一些按以下代码列出的 bundle 。您的 pod 设置中可能还有其他问题。 NSArray *bundles = [[NSBundle mainBundle] pathsForResourcesOfType:@"bundle"inDirectory:nil];
关于ios - [椰子] :Resource Bundle not accessbile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25402782/