ios - [椰子] :Resource Bundle not accessbile

标签 ios objective-c resources cocoapods

在我使用 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/

相关文章:

ios - 属性(property)申报疯狂 iOS 7

c# - 在 ClassLibrary 中使用资源 (resx),无需重新编译即可更改

iOS 应用程序首次启动加载条款和条件

objective-c - Objective-C : Buttons created from subclass of UIButton class not working

iphone - 如何以编程方式获取 Iphone ViewController 大小

resources - 现实生活中有用和无用的开发技术

Javascript 获取页面源(服务器端)

ios - Xcode 4.5 中的 IBAction

iphone - 如何将scrollViewWillBeginDragging限制为仅一个发送者对象?

iphone - 在 iPhone 上打电话并将用户带回应用程序? (UIWebView 做的)