iOS 使用 use_frameworks 后 Bundle 的

2020-08-11  本文已影响0人  天空中的球
一、了解下 use_frameworks
不使用use_frameworks ==> .a
使用use_frameworks ==> framework
  • 用 Cocoapods 导入Swift 框架 到 Swift项目和 Objective-C 项目都必须要 use_frameworks!
  • 用动态库,必须要在 Podfile 文件中添加 use_frameworks!
二、用了 use_frameworks Bundle 之后的影响
三、解决 项目用了 use_frameworks 之后 bundle 改变导致获取不到图片的问题

所以读取的方式,就需要兼容下啦

+ (instancetype)xx_bundleName:(NSString *)bundleName {
    NSURL *associateBundleURL = [[NSBundle mainBundle] URLForResource:@"Frameworks" withExtension:nil];
    associateBundleURL = [associateBundleURL URLByAppendingPathComponent:bundleName];
    associateBundleURL = [associateBundleURL URLByAppendingPathExtension:@"framework"];
    NSBundle *associateBunle = associateBundleURL?[NSBundle bundleWithURL:associateBundleURL]:[NSBundle mainBundle];
    associateBundleURL = [associateBunle URLForResource:bundleName withExtension:@"bundle"];
    NSBundle *bundle = associateBundleURL?[NSBundle bundleWithURL:associateBundleURL]:[NSBundle mainBundle];
    return bundle;
}
+ (instancetype)xx_imgWithName:(NSString *)name bundle:(NSString *)bundleName {
    NSBundle *resource_bundle = [NSBundle xx_bundleName:bundleName];
    UIImage *image = [UIImage imageNamed:name
                                    inBundle:resource_bundle
               compatibleWithTraitCollection:nil];
    return image;
    
}
以上 Bundle 问题,主要是发生在进行组件化或者打静态库的时候,资源文件的处理。
上一篇 下一篇

猜你喜欢

热点阅读