zoukankan      html  css  js  c++  java
  • CocoaPods

    CocoaPods发布框架到远程公有库

    • 1.编写代码~上传远程仓库

      git init
      git add .
      git commit -m '提交到本地分支'
      
      //关联远程仓库
      git remote add origin 远程仓库url
      //提交代码到远程仓库
      git push origin master
      
      //tag
      git tag //查看版本标签
      git tag -a 1.0.0 -m '1.0.0版本完成' //打完tag 还是处于本地,需要   提交远程代码库
      git push --tags //本地所有tags都提交
      
    • 2.创建podSpec

          pod spec create 文件名称
          //修改podspec文件内容,如下 假设项目名称Test01
          s.name         = "Test01"
          s.version      = "1.0.0"
          s.summary      = "Test01 is a test lib"
      
          s.description  = <<-DESC
          "这是一个长的描述字数要比s.summary长,Test01 is a test lib"
          DESC
      
          s.homepage     = "https://github.com/LouKit/Test01"
      
          s.license      = "Apache License, Version 2.0"
          s.author             = { "LK" => "loukit@qq.com" }
          s.source       = { :git => "https://github.com/LouKit/Test01.git", :tag => "#{s.version}" }
          s.source_files  = "Classes", "Classes/**/*.{h,m}"
      
    • 3.podSpec验证

      pod spec lint
      
    • 4.提交到官方索引库

      //邮箱 密码 填个正确即可,后续需要通过邮箱验证
      pod trunk register loukit@qq.com '随便写'  --verbose
      
    • 5.通过trunk推送podspec文件

      pod trunk push 
      
    • 6.完成

      测试
      pod search Test01
      如果搜索不到,干掉缓存json文件(我电脑路径:/Users/loukit/Library/Caches/CocoaPods/search_index.json)继续搜索即可
      

    CocoaPods本地私有库使用

    • 1.创建本地库
    • 2.创建podSpec文件 //pod spec create 文件名称

      修改podspec文件内容同‘CocoaPods发布框架到远程公有库’,其余:
      # 本地库去掉地址即可
      s.source       = { :git => "", :tag => "#{s.version}" }
      
    • 3.验证

      pod lib lint    
      
      出现⚠警告
      localhost:TestLog LouKit$ pod lib lint
      
       -> TestLog (0.0.1)
          - WARN  | homepage: The homepage has not been updated from default
          - WARN  | url: There was a problem validating the URL http://EXAMPLE/TestLog.
          - WARN  | license: Unable to find a license file
      
      [!] TestLog did not pass validation, due to 3 warnings (but you can use `--allow-warnings` to ignore them).
      [!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
          `echo "2.3" > .swift-version`.
      You can use the `--no-clean` option to inspect any issue.
      警告可接受,无视!
      
    • 4.创建测试工程,并创建Podfile文件,进行安装本地库

      platform :ios, '9.0'
      
      target 'Example' do
      use_frameworks!
      #描述好本地相对路径
      pod 'Test01',:path => '../Lib/Test01'
      
      end
      
    • 5.安装

      pod install 
      

    CocoaPods远程私有库使用

    • 1.创建一个专门用于存放spec文件的远程库

    • 2.将远程库地址加入repo

      pod repo add 名字XX 地址
      
    • 3.创建本地模板库

      pod lib create spec文件名称  //记得修改podspec文件
      
    • 4.创建远程库 用于存放 步骤3 存放的库工程

      git add .
      git commit -m 'msg'
      #查看是否有关联远程库,没有需要设置下
      git remote
      //没有设置关联
      git remote add origin 地址
      如:git remote add origin https://git.coding.net/LouKit/xxx.git
      git push origin master  
      
    • 5.验证spec文件

      本地验证 pod lib lint
      远程提交 必须远程验证 pod spec lint (刚刚步骤4提交时没有tag,所以这个步远程验证肯定过不了,需要提交tag)
      
      提交tag:
      git tag 0.1.0
      git push --tags
      //验证
      pod spec lint
      
    • 6.将spec 推送到步骤1的那个私有库

      pod repo push 名字XX spec文件名称.podspec //这里名字XX 必须对应步骤2 那个名字xx
      
    • 7.修改宿主工程podfile

      source 'https://git.coding.net/LouKit/xxx.git'
      source 'https://github.com/CocoaPods/Specs.git'
      platform :ios, '9.0'
      
      target 'Example' do
          use_frameworks!
      
      pod 'spec文件名称'
      end
      
    • 8.安装

      pod install
      

    其他

    问题 1. 维护阶段(扩充代码,版本号升级)

    需重新提交代码 修改spec描述文件,大概步骤如下:
    
    1. 重新提交代码
        git add .
        git commit -m 'msg'
        git push origin master
    
    2. 打tag 同时改spec描述文件
        git tag 0.2.0
        git push --tags
    
    3. 提交pec文件
    
    4. 更新spec文件到索引库
        pod repo push 名字XX spec文件名称.podspec
    

    问题 2. 依赖关系解决(比如制作库需要依赖AFN)

    //直接spec文件描述即可
    s.dependency 'AFNetworking', '~> 3.1.0'
    

    问题 3. 依赖关系子库解决 
    (如一个库里有三个子库,现在只需用到其中一个,不要全部用到 ,即把一个库分成几个小库)

    # 代表分离子库
    #s.source_files = 'xx/Classes/**/*'  这种写法是匹配所有的
    
    s.subspec 'Category' do |c|
        c.source_files = 'xx/Classes/Category/**/*'
    end
    
    s.subspec 'Network' do |n|
        n.source_files = 'xx/Classes/Network/**/*'
        n.dependency 'AFNetworking', '~> 3.1.0'
    end
    
    s.subspec 'Tool' do |t|
        t.source_files = 'xx/Classes/Tool/**/*'
    end
    
    然后使用这个子库过程podefile 写法
    target 'Example' do
    
       use_frameworks!
        pod 'xx/Category'
        pod 'xx/Network'
    end
  • 相关阅读:
    python配置文件INI/TOML/YAML/ENV的区别
    Python中用requests处理cookies的3种方法
    【转】Jenkins报错ModuleNotFoundError: No module named fileName解决办法
    Python中用requests处理cookies的3种方法
    python – 为每个列表元素添加引号
    Python巧用正则表达式,完成接口参数替换
    Python中用OpenPyXL处理Excel表格
    LVM创建及管理
    springcloud --Nacos安装
    springcloud 启动错误
  • 原文地址:https://www.cnblogs.com/baitongtong/p/6681554.html
Copyright © 2011-2022 走看看