I am creating a private library that includes resources that are referenced by components in the library. The library is shared with apps using CocoaPods. In the .podspec for the library, I've included a line like this:
s.resource_bundles = {'IXMapKitResources' => ['IXMapKit/Resources/*']}
One of the resources in the bundle is an asset catalog with multiple image sets, one of which is called 'IXMKAnnotationIcons-Normal-Accident'. The following code returns a nil:
UIImage * image = [UIImage imageNamed: @"IXMKAnnotationIcons-Normal-Accident"];
I found an article on mokacoding.com describing how to load fonts from a pod, but this didn't work for me:
- (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;
}
}
The CocoaPods webpage describing the resources keyword has the following warning:
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.
I'm at a loss of what to do here.