[Cocoapods]:无法访问资源包

时间:2014-08-20 10:48:34

标签: 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始终为零。

我还试图找出是否存在可访问的捆绑包,因此我需要从创建的捆绑包中加载图像,但是:

NSArray *bundles = [[NSBundle mainBundle] pathsForResourcesOfType:@"bundle" inDirectory:nil];

显示没有通过Cocoapods创建捆绑包。

我究竟如何访问这些资源?

2 个答案:

答案 0 :(得分:0)

资源被放入名为“资源”的包中。

s.resource_bundles = {'Resources' => ['MyFramework/Resources/**/*.{xib, png, jpeg, jpg}']}

您可以通过以下代码访问该包

NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle]
                                                 pathForResource:@"Resources"      
                                                          ofType:@"bundle"]];

s.resource_bundles中的密钥是捆绑名称。

注意: 我有一些由以下代码列出的包。您的广告连播设置中可能还有其他问题。     NSArray * bundles = [[NSBundle mainBundle] pathsForResourcesOfType:@" bundle" inDirectory:无];

答案 1 :(得分:0)

要从捆绑中加载图像,请使用:

UIImage *testImage = [UIImage imageNamed:@"Resources.bundle/testImage.jpeg"];
相关问题