美文网首页程序员
创建Cocoapods私人仓库

创建Cocoapods私人仓库

作者: FlyOceanFish | 来源:发表于2017-10-25 21:13 被阅读51次

    之前有一篇介绍了怎么创建私人项目手把手教你创建podspec,创建成功之后进行发布。最终发布
    到Cocoapods官方仓库中。但是有时候我们创建完自己的pod项目之后,并不想公开发布,只限于自己或者公司使用,这时候就需要我们创建自己的私人仓库,将pod项目发布到自己的私人仓库中。

    创建一个git私人项目

    由于github只能创建公开项目,如果要创建私人项目是要花钱的,所以我这边使用的是码市,免费最多能
    创建5个私人项目,挺不错的。这个私人项目是我们用来存储spec的总仓库

    创建podspec

    • 创建spec工程

    pod lib create [名称]

    这个与pod spec create的区别其实就是帮我们拉了一个模板,确实能省很多事情,里边包括了一个Example工程

    • 再创建一个git私人项目

    这个是用来存放我们Xcode工程和代码的。说白了就是托管我们代码的地方,主要是用来配饰spec中s.source用的

    • 将我们要公开的代码和Example提交到git仓库

    在第一步我们创建的工程中执行

    git add .

    git commit -m 'init'

    git remote add orgin [刚才我们创建仓库的地址]

    git push origin master

    到这里为止已经将我们的代码提交到刚才创建的代码仓库中了。(如果没有权限则要配置.ssh中公钥私钥)
    由于spec文件的原因我们其实还有一步没有做,其实就是打tag,只有打了tag才行,:tag => s.version.to_s就是这句话用到的
    接下来我们继续打tag

    git tag 0.1.0

    git push --tags

    编写xx.podspec文件

    #
    # Be sure to run `pod lib lint Utils.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 http://guides.cocoapods.org/syntax/podspec.html
    #
    
    Pod::Spec.new do |s|
      s.name             = 'Utils'
      s.version          = '0.1.0'
      s.summary          = 'Utils.'
    
    # 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
    Utils封装常用组件
                           DESC
    
      s.homepage         = 'https://coding.net/u/FlyOceanFish/p/Utils'
      # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
      s.license          = { :type => 'MIT', :file => 'LICENSE' }
      s.author           = { 'FlyOceanFish' => '978456068@126.com' }
      s.source           = { :git => 'https://git.coding.net/FlyOceanFish/Utils.git', :tag => s.version.to_s }
      # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
    
      s.ios.deployment_target = '8.0'
    
      s.source_files = 'Utils/Classes/**/*'
    
      # s.resource_bundles = {
      #   'Utils' => ['Utils/Assets/*.png']
      # }
    
      # s.public_header_files = 'Pod/Classes/**/*.h'
        s.frameworks = 'UIKit', 'MapKit'
      # s.dependency 'AFNetworking', '~> 2.3'
    end
    
    

    这个是我写的,也可以参考我之前的一篇文章

    检验spec文件的合法性

    pod spec lint

    如果有什么错误,可以参照提示修改就行了

    发布我们的podspec文件到我们的私人仓库

    • 首先添加私人仓库源

    这个私人仓库源其实就是我们第一步创建的那个仓库地址

    pod repo

    这个命令可以看到我们目前的私人仓库源

    pod repo add [仓库源名称][仓库地址]

    比如:

    pod repo add FlyOceanSpecs https://git.coding.net/FlyOceanFish/FlyOceanSpecs.git

    仓库源随便起名字,不过这个我们发布我们的spec项目的时候用的到。仓库地址就是我们
    第一步创建的那个git仓库地址

    • 发布到私人仓库

    接上一步我们的FlyOceanSpecs仓库源

    pod repo push FlyOceanSpecs Utils.podspec

    使用

    我的Podfile文件如下:

    # Uncomment the next line to define a global platform for your project
     platform :ios, '9.0'
     source 'https://git.coding.net/FlyOceanFish/FlyOceanSpecs.git'
     source 'https://github.com/CocoaPods/Specs.git'
    target 'test' do
      # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
       use_frameworks!
      pod 'YTOBaiduMapKit'
      # Pods for test
    
    end
    

    这就可以正常使用了

    总结

    这个过程其实还是挺复杂的,大家如果有什么问题可以给我留言,我会及时回复的

    注:
    以上是我制作的一个YTOBaiduMapKit,由于百度api针对pod导入只支持全量导入,这样则会导致整个包比较大,所以我制作了一个阉割版,只包括了BaiduMapAPI_BaseBaiduMapAPI_LocationBaiduMapAPI_Map这三个包就是百度基础功能和定位的功能

    相关文章

      网友评论

        本文标题: 创建Cocoapods私人仓库

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