ios - 在cocoapods中加载resource_bundle错误

标签 ios objective-c cocoapods nsbundle

我正在尝试制作自己的cocoapods,我使用了图像。 当我按照教程操作时,出现错误。

.podspec

  s.resource_bundles = {
    'SSSlidingSelector' => ['SSSlidingSelector/Assets/*.xcassets']
  }

类/SlidingSelector.m

- (UIImage *)getImageWithName:(NSString *)imageName {
    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    NSURL *url = [bundle URLForResource:@"SSSlidingSelector" withExtension:@"bundle"];
    NSBundle *targetBundle = [NSBundle bundleWithURL:url];
    UIImage *image = [UIImage imageNamed:imageName
                                inBundle:targetBundle
           compatibleWithTraitCollection:nil];
    return image;
}

错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSBundle initWithURL:]: nil URL argument'

屏幕截图 Resource path enter image description here

我的代码有什么问题吗? 谢谢

最佳答案

你的代码没有问题。

Cocoapods 1.0.1 版支持 Assets 目录。请检查您的版本是否低于在终端中运行 pod --version 的版本。

如果新的 pod 安装 未解决,则 Assets 目录上的 xCode 新构建系统(如所述 Here )存在问题,这可能是您的问题。

您可以在文件 > 工作区设置... > 构建系统上更改构建系统。尝试将其设置为旧版构建系统

enter image description here

关于ios - 在cocoapods中加载resource_bundle错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57833676/

相关文章:

xcode - 如何使用 cocoapods 保存源文件目录(或组)中的组织?

iphone - 从 iPhone 上传文件时出现 POSIX 错误 12 ("Cannot allocate memory"

ios - 在 Objective C 中创建负数数组

ios - 不区分大小写的字符串搜索 - iphone

iphone - 核心数据的数据迁移

ios - 如何强制 CocoaPods 使用二进制版本的 Facebook 和 Parse SDK?

html - 媒体查询 - iOS 设备

iphone - 自定义 View Controller 委托(delegate)不起作用

objective-c - 初学者哪个更容易 : RubyCocoa or ObjC/Cocoa

ios - 使用 Xcode 9 和 AES 解密的 CryptoSwift