01.podspec设置
s.resource_bundles = {
'mysdkbundle' => ['xxxx/xxxx.xcassets']
}
02如何 使用
当Podfile 中 #use_frameworks! 时
+ (UIImage *)dp_imageNamed:(NSString *)name {
NSString *path = [[NSBundle mainBundle] pathForResource:@"mysdkbundle" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
UIImage *image = [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
}
当Podfile 中 use_frameworks! 时
+ (UIImage *)dp_imageNamed:(NSString *)name {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Frameworks/pod模块名.framework/mysdkbundle" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
UIImage *image = [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
}
03综上可以这样处理
+ (UIImage *)dp_imageNamed:(NSString *)name {
//#use_frameworks!
NSString *path = [[NSBundle mainBundle] pathForResource:@"mysdkbundle" ofType:@"bundle"];
if(!path){
//use_frameworks!
path = [[NSBundle mainBundle] pathForResource:@"Frameworks/pod模块名.framework/mysdkbundle" ofType:@"bundle"];
}
NSBundle *bundle = [NSBundle bundleWithPath:path];
UIImage *image = [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
if (!image) {//都获取不到时,尝试从主app中获取
image = [UIImage imageNamed:name];
}
}