美文网首页
iOS本地库和远程库

iOS本地库和远程库

作者: 雷霸龙 | 来源:发表于2021-03-08 17:26 被阅读0次

    一、本地库

    1、创建本地库

    选择一个文件夹,比如在桌面创建了一个Lib的文件夹,cd到Lib目录,然后创建本地库。

    // YHUtils就是所创建的本地库的名字
    pod lib create YHUtils
    

    创建完成之后就会自动打开示例工程

    2、替换文件

    ReplaceMe.m文件删除,把自己的文件添加进来。

    3、引用第三方

    如果自己的本地库引用了其他第三方库,就需要在示例工程里添加第三方,在Podfile文件里添加,比如:

    pod 'SDWebImage', '~> 3.7.5'
    

    注意:use_frameworks!,如果是动态库则用use_frameworks!,如果是静态库则用#use_frameworks!,咱们用的基本都是#use_frameworks!
    新加入了第三方或者本地库有修改等,需要cd到示例工程,pod install一下。

    二、远程库

    1、查看本地索引库
    pod repo
    
    2、添加私有索引库

    必须创建一个远程库,如:YHSpecs来管理Specs文件

    pod repo add YHSpecs https://github.com/zhizunbaoyinhao/YHSpecs.git
    

    创建成功之后,可以在本地的.cocopods/repos/目录中看到YHSpecs文件夹。

    3、创建项目的远程库

    在GitHub上创建一个项目,名字和本地库一样,这里用的是YHUtils

    4、修改.podspec文件

    打开示例工程,找到YHUtils.podspec文件,把里面相应的东西修改一下:

    #
    # Be sure to run `pod lib lint YHUtils.podspec' to ensure this is a
    # valid spec before submitting.
    #
    # Any lines starting with a # are optional, but their use is encouraged
    # To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
    #
    
    Pod::Spec.new do |s|
      s.name             = 'YHUtils'
      s.version          = '0.1.0'
      s.summary          = '一个简短的描述'
    
    # This description is used to generate tags and improve search results.
    #   * Think: What does it do? Why did you write it? What is the focus?
    #   * Try to keep it short, snappy and to the point.
    #   * Write the description between the DESC delimiters below.
    #   * Finally, don't worry about the indent, CocoaPods strips it!
    
      s.description      = <<-DESC
    详细的描述
                           DESC
    
      s.homepage         = 'https://github.com/zhizunbaoyinhao/YHUtils.git'
      # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
      s.license          = { :type => 'MIT', :file => 'LICENSE' }
      s.author           = { '153220837@qq.com' => 'yinhao6@jd.com' }
      s.source           = { :git => 'https://github.com/zhizunbaoyinhao/YHUtils.git', :tag => s.version.to_s }
      # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
    
      s.ios.deployment_target = '9.0'
    
      s.source_files = 'YHUtils/Classes/**/*'
      
      # s.resource_bundles = {
      #   'YHUtils' => ['YHUtils/Assets/*.png']
      # }
    
      # s.public_header_files = 'Pod/Classes/**/*.h'
      # s.frameworks = 'UIKit', 'MapKit'
      # s.dependency 'AFNetworking', '~> 2.3'
      s.dependency 'SDWebImage', '~> 3.7.5'
    end
    
    5、上传组件代码

    cd到本地库的根目录,对于本文来说就是Lib/YHUtils目录,下面依次执行

    cd /Users/yinhao6/Desktop/Lib/YHUtils
    git add .
    git commit -m '初始化'
    git remote add origin https://github.com/zhizunbaoyinhao/YHUtils.git
    git push origin master -f
    

    如果是第一次的话,可能要输入git的账号密码,输入,然后等待,就可以提交成功了。

    6、打tag
    git tag '0.1.0' //这个版本号必须和spec中的 “s.version” 一致
    git push --tags
    
    7、本地验证Spec的必填字段和远程验证
    // 本地验证不会验证s.source中的tag
    pod lib lint
    // 远程验证会验证s.source中的tag,如果此时没有打上相应的标签则会报错
    pod spec lint
    
    如果验证的是私有库,则在后面加上--private,否则会有警告,你可以选择--allow-warnings来忽略该警告
    pod lib lint --private
    pod spec lint --private
    pod lib lint --allow-warnings
    pod spec lint --allow-warnings
    pod lib lint --private --allow-warnings
    pod spec lint --private --allow-warnings
    pod lib lint --private --allow-warnings --no-clean --verbose
    pod spec lint --private --allow-warnings --verbose
    
    8、提交podspec到私有索引库

    这个终端必须在本地库的根目录下,cd到本地库的根目录,对于本文来说就是Lib/YHUtils目录

    // pod repo push 私有索引库名称 spec名称.podspec
    pod repo push YHSpecs YHUtils.podspec
    // 如果报错,选择以下方式
    pod repo push YHSpecs YHUtils.podspec --verbose --allow-warnings
    

    提交成功之后,去GitHub上看看YHSpecs,可以看到成功了。


    image.png
    // 可以pod search搜索到YHUtils,如果搜索不到,可以更新一下本地库
    pod repo update
    // 只安装新添加的库
    pod install --verbose --no-repo-update
    // 会在安装相关库时,更新其他库版本
    pod update --verbose --no-repo-update
    // 只更新指定的库,其它库忽略
    pod update 库名 --verbose --no-repo-update
    pod update YHUtils --verbose --no-repo-update
    
    9、使用自己创建的私有库

    在需要使用私有库的Podfile文件里引入源和pod私有库名称版本,比如:

    source 'https://github.com/zhizunbaoyinhao/YHSpecs.git'
    source 'https://github.com/CocoaPods/Specs.git'
    # Uncomment the next line to define a global platform for your project
    # platform :ios, '9.0'
    
    target 'test' do
      # Comment the next line if you don't want to use dynamic frameworks
      use_frameworks!
    
      # Pods for test
      pod 'SDWebImage', '~> 3.7.5'
      pod 'YHUtils'
    
    end
    

    三、更新版本

    1、修改.podspec文件

    打开示例工程,找到YHUtils.podspec文件,把里面相应的东西修改一下,项目的内容和.podspec文件修改之后,需要pod install一下,看看示例工程能不能正常运行,可以的话就说明可以了。

    2、上传更新的组件代码

    cd到本地库的根目录,对于本文来说就是Lib/YHUtils目录,下面依次执行

    cd /Users/yinhao6/Desktop/Lib/YHUtils
    git add .
    git commit -m '版本更新测试'
    git push origin master -f
    
    3、打tag
    git tag '0.1.1' //这个版本号必须和spec中的 “s.version” 一致
    git push --tags
    
    4、提交podspec到私有索引库

    这个终端必须在本地库的根目录下,cd到本地库的根目录,对于本文来说就是Lib/YHUtils目录

    // pod repo push 私有索引库名称 spec名称.podspec
    pod repo push YHSpecs YHUtils.podspec
    // 如果报错,选择以下方式
    pod repo push YHSpecs YHUtils.podspec --verbose --allow-warnings
    

    这就版本更新成功了。

    相关文章

      网友评论

          本文标题:iOS本地库和远程库

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