我想将图像资源包含在 cocoapod 库中,但访问它们时遇到问题。我已阅读这些资源来寻求帮助:
Cocoapods 资源 http://guides.cocoapods.org/syntax/podspec.html#resources
Cocoapods 资源包 http://guides.cocoapods.org/syntax/podspec.html#resource_bundles
Mokacoding 资源包 http://www.mokacoding.com/2014/02/13/sharing-assets-with-cocoapods-resource-bundle-and-dynamically-loaded-fonts.html
大卫·波特资源包 https://stackoverflow.com/questions/23835052/load-image-from-cocoapods-resource-bundle
然而,没有人指出我访问资源的方向。我尝试过以下方法:
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle bundleWithIdentifier:@"Assets"] URLForResource:@"my-image@2x" withExtension:@"png"]]]
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle bundleWithIdentifier:@"Assets"] URLForResource:@"my-image" withExtension:@"png"]]]
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle bundleWithIdentifier:@"Assets.bundle"] URLForResource:@"my-image" withExtension:@"png"]]]
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle mainBundle] URLForResource:@"my-image" withExtension:@"png"]]]
[[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle mainBundle] URLForResource:@"my-image@2x" withExtension:@"png"]]]
[UIImage imageNamed:@"my-asset"]
[UIImage imageNamed:@"[email protected] /cdn-cgi/l/email-protection"]
但它们都不起作用。
我已经使用这些替代方案设置了我的 podspec,但两者都不适用于上述方案:
s.resources = ['Pod/Assets/*.{png, jpg}', 'Pod/Assets/**/*.{png, jpg}']
s.resource_bundles = {
'Assets' => ['Pod/Assets/*.{png, jpg}', 'Pod/Assets/**/*.{png, jpg}']
}
资源显示在“开发 Pods/我的应用程序/资源”下pod update
,但我一生都无法访问它们。没有任何捆绑包,也没有任何名为“资产”的东西。
任何帮助或指导将不胜感激。