我正在尝试制作自己的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'
我的代码有什么问题吗? 谢谢
最佳答案
你的代码没有问题。
Cocoapods 1.0.1 版支持 Assets 目录。请检查您的版本是否低于在终端中运行 pod --version
的版本。
如果新的 pod 安装
未解决,则 Assets 目录上的 xCode 新构建系统(如所述 Here )存在问题,这可能是您的问题。
您可以在文件
> 工作区设置...
> 构建系统
上更改构建系统。尝试将其设置为旧版构建系统
。
关于ios - 在cocoapods中加载resource_bundle错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57833676/