美文网首页
上传代码到CocoaPods库时遇到的问题总结

上传代码到CocoaPods库时遇到的问题总结

作者: 老刘了 | 来源:发表于2018-05-08 15:38 被阅读30次

    上传cocoapods引用第三方时遇到的错误

        - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
        - ERROR | xcodebuild:  /Users/isaac/Library/Developer/Xcode/DerivedData/App-fndikxwvwpulrwgjwibzdoqkkejs/Build/Products/Release-iphonesimulator/ISGCategory/ISGCategory.framework/Headers/MBProgressHUD+ISGProgress.h:10:9: error: include of non-modular header inside framework module 'ISGCategory.MBProgressHUD_ISGProgress': '/Users/isaac/Library/Developer/Xcode/DerivedData/App-fndikxwvwpulrwgjwibzdoqkkejs/Build/Products/Release-iphonesimulator/MBProgressHUD/MBProgressHUD.framework/Headers/MBProgressHUD.h' [-Werror,-Wnon-modular-include-in-framework-module]
        - NOTE  | xcodebuild:  /var/folders/5f/19hn47zd3gd3n7qz6l75hqzm0000gn/T/CocoaPods-Lint-20180508-13642-1ycastd-ISGCategory/App/main.m:3:9: fatal error: could not build module 'ISGCategory'
    
    本地检测代码仓库是否有问题
    pod lib lint --allow-warnings --use-libraries
    
    远程检测代码仓库是否有问题
    pod spec lint --allow-warnings --use-libraries
    
    向远程代码索引库提交spec
    pod trunk push --allow-warnings --use-libraries
    

    参考资料

    上传代码到CocoaPods库

    Pod资源文件Bundle的正确读取

    刚上传以后发现无法获取到图片,尝试了很多方法使用bundle等等

    [UIImage imageNamed:]  // 获取的UIImage总是nil
    

    查了很多资料没有解决,最终在 Pod资源文件的正确Bundle读取获得了解决方法
    添加了一个NSBundle的分类成功获取到了图片

    下面上代码

    NSBundle+ISGPodBundle.h
    
    
    /**
     获取文件所在name,默认情况下podName和bundlename相同,传一个即可
     
     @param bundleName bundle名字,就是在resource_bundles里面的名字
     @param podName pod的名字
     @return bundle
     */
    + (NSBundle *)bundleWithBundleName:(NSString *)bundleName
                               podName:(NSString *)podName;
    
    NSBundle+ISGPodBundle.m
    
    + (NSBundle *)bundleWithBundleName:(NSString *)bundleName podName:(NSString *)podName { 
        if (bundleName == nil && podName == nil) {
            @throw @"bundleName和podName不能同时为空";
        }else if (bundleName == nil ) {
            bundleName = podName;
        }else if (podName == nil) {
            podName = bundleName;
        }
        
        
        if ([bundleName containsString:@".bundle"]) {
            bundleName = [bundleName componentsSeparatedByString:@".bundle"].firstObject;
        }
        //没使用framwork的情况下
        NSURL *associateBundleURL = [[NSBundle mainBundle] URLForResource:bundleName withExtension:@"bundle"];
        //使用framework形式
        if (!associateBundleURL) {
            associateBundleURL = [[NSBundle mainBundle] URLForResource:@"Frameworks" withExtension:nil];
            associateBundleURL = [associateBundleURL URLByAppendingPathComponent:podName];
            associateBundleURL = [associateBundleURL URLByAppendingPathExtension:@"framework"];
            NSBundle *associateBunle = [NSBundle bundleWithURL:associateBundleURL];
            associateBundleURL = [associateBunle URLForResource:bundleName withExtension:@"bundle"];
        }
        
        NSAssert(associateBundleURL, @"取不到关联bundle");
        //生产环境直接返回空
        return associateBundleURL?[NSBundle bundleWithURL:associateBundleURL]:nil;
    }
    

    获取图片方法:

    
        NSBundle *bundle = [NSBundle bundleWithBundleName:nil podName:@"ISGCategory"];
        
        NSString *path = [[bundle resourcePath] stringByAppendingPathComponent:icon];
        
        UIImage *img = [UIImage imageWithContentsOfFile:path];
    

    参考资料

    Pod资源文件的正确Bundle读取

    相关文章

      网友评论

          本文标题:上传代码到CocoaPods库时遇到的问题总结

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