美文网首页
pod 模块开发注意事项

pod 模块开发注意事项

作者: 鸿伟x | 来源:发表于2019-11-13 12:22 被阅读0次

    坑1: pod模块中bundle资源的路径

    在主项目中 podfile 文件里
    加入use_frameworks!时

    use_frameworks!  #会把资源都打包自己的framework中的bundle里
    #此时bundle的路径为 xxx.app/DPSDKKIT.framework/DPSDKKIT.bundle
    

    未加入use_frameworks!时

    #use_frameworks!  #会把资源都打包在mainbundle里
    #此时bundle的路径为 xxx.app/DPSDKKIT.bundle
    

    所以如果在pod模块中用到的文件存在了bundle里

    例如:

    .podspec文件里

      s.resource_bundles = {
        'DPSDKKIT' =>   ['DPSDKKIT/xxxxx.xcassets']
      }
    

    当需要调用xxxxx.xcassets里的资源时,要这样使用

    + (UIImage *)dpImageNamed:(NSString *)name {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"DPSDKKIT" ofType:@"bundle"]; 
        if(!path){
            path = [[NSBundle mainBundle] pathForResource:@"Frameworks/DPSDKKIT.framework/DPSDKKIT" ofType:@"bundle"];
        }
        NSBundle *bundle = [NSBundle bundleWithPath:path];
        UIImage *image = [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
        if (!image) {
            image = [UIImage imageNamed:name];
        }
        return image;
    }
    

    坑2:(未完待续)

    相关文章

      网友评论

          本文标题:pod 模块开发注意事项

          本文链接:https://www.haomeiwen.com/subject/xwehictx.html