我正在创建一个私有库,其中包含库中组件引用的资源.该图书馆与使用CocoaPods的应用程序共享.在图书馆的.podspec中,我已经添加了一行:
s.resource_bundles = {'IXMapKitResources' => ['IXMapKit/Resources/*']}
包中的一个资源是具有多个映像集的资产目录,其中一个称为“IXMKAnnotationIcons-Normal-Accident”.以下代码返回一个零:
UIImage * image = [UIImage imageNamed: @"IXMKAnnotationIcons-Normal-Accident"];
我发现一个article on mokacoding.com描述如何从一个pod加载字体,但这对我来说没有效果:
- (UIImage *) ixmk_imageNamed: (NSString *) name { NSString * IXMKResourceBundleName = @"IXMapKitResources.bundle"; NSString * resourceName = [NSString stringWithFormat: @"%@/%@",IXMKResourceBundleName,name]; NSString * imageTypeString = [self ixmk_stringForImageType: imageType]; NSURL * url = [[NSBundle mainBundle] URLForResource: resourceName withExtension: imageTypeString]; NSData * imageData = [NSData dataWithContentsOfURL: url]; if (imageData != nil) { CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef) imageData); CGImageRef imageRef = [self ixmk_imageFromDataProvider: provider imageType: imageType]; UIImage * image = [UIImage imageWithCGImage: imageRef]; CFRelease(imageRef); CFRelease(provider); return image; } else { return nil; } }
CocoaPods webpage describing the resources keyword有以下警告:
We strongly recommend library developers to adopt resource bundles as
there can be name collisions using the resources attribute. Moreover
resources specified with this attribute are copied directly to the
client target and therefore they are not optimized by Xcode.
我在这里做什么是失败的.