美文网首页
2019-01-25 pod私有库技术扩展

2019-01-25 pod私有库技术扩展

作者: 幸福晓杰2016 | 来源:发表于2019-01-25 16:13 被阅读12次

    扩展一:使用.podspec文件来支持依赖本地其他项目文件(xcodeproj),实现在一个workSpace下联调:
    首先创建一个小项目myDemo,然后在myDemo.xcodeproj的同级目录下,创建
    myDemo.podspec
    文件内容配置如下:(按照注释修改即可)

    Pod::Spec.new do |s|
    
      s.name         = "myDemo"
      s.version      = "0.0.1"
      s.summary      = "#{s.name}"
    
    
      s.description  = "#{s.name}"
    
      s.homepage     = "http://#{s.name}"
    
      s.license      = "MIT"
      # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }
    
    
      s.author             = { "" => "" }
    
    
      s.source       = { :git => "", :tag => "#{s.version}" }
    
      s.source_files  = "#{s.name}/Classes/**/*.swift"// 关键:对外开放的文件写在myDemo/Classes/下面所有的子文件夹中
      # s.exclude_files = "#{s.name}/Classes/Exclude"
    
      # s.public_header_files = "Classes/**/*.h"
    
      #s.resource  = "#{s.name}/Assets/*.xcassets"
      s.resources = "#{s.name}/Classes/**/*.{xcassets}"//关键:对外开放的资源都放在myDemo/Classes/下面所有的子文件夹中
    
      # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
    
    
    
      # s.framework  = "SomeFramework"
      # s.frameworks = "SomeFramework", "AnotherFramework"
    
      # s.library   = "iconv"
      # s.libraries = "iconv", "xml2"
    
    
      # s.requires_arc = true
    
      # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
      
    //下面写是myDemo依赖的第三方组件
      s.dependency "DeviceKit","~>1.10.0"
      s.dependency "RxSwift","~>4.4.0"
      s.dependency "RxCocoa","~>4.4.0"
      s.dependency "SnapKit","~>4.2.0"
      s.dependency "Then","~>2.4.0"
    end
    

    使用方法:
    在你的mainProject目录中podfile中写入:
    pod 'myDemo',:path => '../myDemo/'
    path =>后面引号内容,是文件相对于podfile所在的路径,这个路径规则类似vue.js的文件导入规则。
    这样在mainProject目录 执行pod install,你就会发现,第三方依赖于你的myDemo对外开放的文件都集成到mainProject.workSpace下面了。

    扩展二:支持在局域网,建立自己的私有库。这样做的好处是即使没有网的情况下,也可以使用cocoapod进行更新
    以MJRefresh为例
    git clong https://github.com/CoderMJLee/MJRefresh.git
    git remote add newRemote #myGit仓库#
    git push newRemote
    git push newRemote --tags
    剩下的是建立索引库,就是podfile文件最上方的 source地址
    如:source '你的git仓库地址'
    如:source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'取得清华的镜像仓库

    其实索引库也是一个Git仓库,不过里面存的是索引文件(podspec.json)不是真正的代码。假设这个仓库叫仓库2
    打开本地文件路径 /Users/#MacUserName#/.cocoapods/repos/master/Specs
    我们可以看到里面建立的索引库。
    在这个路径下搜索:MJREfresh
    我们可搜到很多文件夹,只有一个是真的,其他的都是在MJREfresh变形的。
    打开后,我们会发现每个tag对应一个文件夹
    如3.1.15.7文件夹里面的文件是:MJRefresh.podspec.json

    {
      "name": "MJRefresh",
      "version": "3.1.15.7",
      "summary": "An easy way to use pull-to-refresh",
      "homepage": "https://github.com/CoderMJLee/MJRefresh",
      "license": "MIT",
      "authors": {
        "MJ Lee": "richermj123go@vip.qq.com"
      },
      "platforms": {
        "ios": "6.0"
      },
      "source": {
        "git": "https://github.com/CoderMJLee/MJRefresh.git",//关键点是这里,这里改成之前你上传MJ代码的仓库地址即可
        "tag": "3.1.15.7"
      },
      "source_files": "MJRefresh/**/*.{h,m}",
      "resources": "MJRefresh/MJRefresh.bundle",
      "requires_arc": true
    }
    

    按照上面的注释修改即可

    然后将你的文件夹(MJREfresh->MJRefresh.podspec.json)上传至你的私有仓库2中,那么即使不能连外网,我们也可以podfile上加上
    source 'http://git.xxx.com.cn/myPods/mySpecs.git'
    这样你可以更新到MJRefresh的3.1.15.7的版本了。

    相关文章

      网友评论

          本文标题:2019-01-25 pod私有库技术扩展

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