ios – 从CocoaPods资源束加载映像

我正在创建一个私有库,其中包含库中组件引用的资源.该图书馆与使用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.

我在这里做什么是失败的.

解决方法

这可能是资产目录的问题,而不是CocoaPods或bundle.将图像从资产目录中移出可以解决问题. Apple似乎不支持二级资源包中的资产目录.可怜.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...