使用码云(git.oschina)做私有的CocoaPods仓库

CocoaChina

简书

首先感谢两位的文章对我的帮助!

想弄自己的CocoaPods仓库很久了,因为我们公司产品有两个端,很多代码都是相似的,有时直接是复制粘贴过来是很不方便的,经常改动又没想到封装成静态库文件,之前也尝试过很多次,总是失败,所以这次我也会把自己之前踩的坑分享出来.

1.在码云上注册自己的帐号


2.首先创建一个项目放置spec(之前创建就是没明白这个关系,这个详细后面用到讲)


最好选择初始化项目,后面会方便很多.

然后得到地址 https://git.oschina.net/sch1111878/private-specs.git


3.再新建一个项目  (github上的repository,)这个是用来存放我们用到的类文件的

和第二步比较相似不贴图了,注意这个名称是不能重复的,所以点击创建前在 pod search xxx 来搜索下是比较靠谱的,我用的是 SCHPodsTest


这样就是别人没有注册的.

我们得到https://git.oschina.net/sch1111878/schpodstest.git

4.把第三步创建的项目拷贝下来,我使用的SourceTree来管理Git,比较简单,

从url克隆就可以了,然后打开本地目录,

然后提交,记得一个要打tag 值,对应的下面的 s.version

这里我们建一个自己的类,目录如下


然后键入

pod spec create SCHPodsTest
然后就会多出一个.podspec 文件,

然后编辑他,我使用的是sublime

#
#  Be sure to run `pod spec lint SCHPodsTest.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  s.name         = "SCHPodsTest"


  # 这个地方一定要注意了,你的git提交要打上对应的tag值才能拉取
  s.version      = "0.0.1" 
  s.summary      = "A short description of SCHPodsTest."

  # 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
  演示Demo
                   DESC

  s.homepage     = "http://EXAMPLE/SCHPodsTest"
  # s.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See http://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  s.license      = "MIT"
  # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  s.author             = { "blank" => "[email protected]" }
  # Or just: s.author    = "blank"
  # s.authors            = { "blank" => "[email protected]" }
  # s.social_media_url   = "http://twitter.com/blank"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  s.platform     = :ios
  s.platform     = :ios, "5.0"

  #  When using multiple platforms
  # s.ios.deployment_target = "5.0"
  # s.osx.deployment_target = "10.7"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  s.source       = { :git => "https://git.oschina.net/sch1111878/schpodstest.git", :tag => "#{s.version}" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #

  s.source_files  = "Classes", "Classes/**/*.{h,m}"
  s.exclude_files = "Classes/Exclude"

  # s.public_header_files = "Classes/**/*.h"


  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #

  # s.resource  = "icon.png"
  # s.resources = "Resources/*.png"

  # s.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  s.framework  = "UIKit"
  # s.frameworks = "SomeFramework", "AnotherFramework"

  # s.library   = "iconv"
  # s.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

  s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  # s.dependency "JSONKit", "~> 1.4"

end

我把全部的都粘贴上了, 这里要注意的几个点是

 * platform

 * source

 * framework

然后就可以执行 pod spec lint 来检查, 如果有Error 看内容修改,这个修改对应就好了,想起以前做这个看到错误就直接卡住了,warn是可以忽略的,假如只有warn,

我这里突然蹦一个Swift版本不对,无视就可以了.

使用pod spec lint --allow-warnings 就可以了,

如果看到提示 passed validating 就是通过了.

然后就用到第一次的那个repo了,

pod repo add uupt https://git.oschina.net/sch1111878/private-specs.git

通过 pod repo list 查看是否成功


然后 pod repo push uupt xxx.podspec --allow-warnings

等提示推送完成,就可以用的,


Podfile中 最顶部加入我们的私有 https://git.oschina.net/sch1111878/private-specs.git

然后 pod 'SCHPodsTest' 

不出以外就能看到成功了.

以后修改文件时提交改tag值就可以了.


如果有其他问题可以私信或评论问我

你可能感兴趣的:(iOS)