iOS - cocoa pods 的使用

2017-10-07  本文已影响41人  黄晓坚

cocoapods官网查看

pod spec create TestLib

Snip20171003_1.png Snip20171003_2.png
  s.name         = "TestLib"  // 名称
  s.version      = "0.0.1"    // 版本
  s.summary      = "A short description of TestLib."  // 简介
  s.description  = “TestLib, 这个是详细描述 一定要注意! 字数比s.summary长 ”

  s.homepage     = "https://github.com/Mrhuangchina/testFiel" // 首页 以TestLib结尾。即以spec描述文件名称结尾 可以换成仓库地址
  s.license      = "MIT"
  s.author             = { "Mrhuangchina" => "xxxx@qq.com" } //这里的是你的Github里的名字 还要你的登录帐号邮箱
  Or just: s.author    = "Mrhuangchina"
  s.authors            = { "Mrhuangchina" => "xxxx@qq.com" }  //这里的是你的Github里的名字 还要你的登录帐号邮箱
       // source 这里 将改成你的spec描述文件的仓库地址  tag 和s.version 版本 保持一致 也就是Github仓库中的releases版本号
  s.source       = { :git => "https://github.com/Mrhuangchina/testFiel.git", :tag => "#{s.version}" }
        // 在指定该的文件中 ** 通配符 标示目录 *.{h,m}:* 代表的是文件夹
  s.source_files  = "Classes", "Classes/**/*.{h,m}"
  s.exclude_files = "Classes/Exclude"

Pod::Spec.new do |s|
  s.name             = "PodTestLibrary"    #名称
  s.version          = "0.1.0"             #版本号
  s.summary          = "Just Testing."     #简短介绍,下面是详细介绍
  s.description      = <<-DESC
                       Testing Private Podspec.
 
                       * Markdown format.
                       * Don't worry about the indent, we strip it!
                       DESC
  s.homepage         = "https://coding.net/u/wtlucky/p/podTestLibrary"                           #主页,这里要填写可以访问到的地址,不然验证不通过
  # s.screenshots     = "www.example.com/screenshots_1", "www.example.com/screenshots_2"           #截图
  s.license          = 'MIT'              #开源协议
  s.author           = { "wtlucky" => "wtlucky@foxmail.com" }                   #作者信息
  s.source           = { :git => "https://coding.net/wtlucky/podTestLibrary.git", :tag => "0.1.0" }      #项目地址,这里不支持ssh的地址,验证不通过,只支持HTTP和HTTPS,最好使用HTTPS
  # s.social_media_url = 'https://twitter.com/<twitter_username>'                       #多媒体介绍地址
 
  s.platform     = :ios, '7.0'            #支持的平台及版本
  s.requires_arc = true                   #是否使用ARC,如果指定具体文件,则具体的问题使用ARC
 
  s.source_files = 'Pod/Classes/**/*'     #代码源文件地址,**/*表示Classes目录及其子目录下所有文件,如果有多个目录下则用逗号分开,如果需要在项目中分组显示,这里也要做相应的设置
  s.resource_bundles = {
    'PodTestLibrary' => ['Pod/Assets/*.png']
  }                                       #资源文件地址
 
  s.public_header_files = 'Pod/Classes/**/*.h'   #公开头文件地址
  s.frameworks = 'UIKit'                  #所需的framework,多个用逗号隔开
  s.dependency 'AFNetworking', '~> 2.3'   #依赖关系,该项目所依赖的其他库,如果有多个需要填写多个s.dependency
end</twitter_username>
Snip20171003_4.png
git tag '0.0.1'   //设置tag 并且tag值必须和spec描述文件version一致
git push --tags  // 将tag 值 push 到远程仓库。
Snip20171003_5.png Snip20171003_6.png
$ pod trunk register orta@cocoapods.org 'Orta Therox' --description='macbook air'  // 即下面这行解释  description 描述信息(可写可不写)
$ pod trunk register 邮箱地址 '名字' --verbose  //--verbose 打印一些详细信息

Snip20171003_8.png

在你刚刚填写的邮箱中打开收到的邮件注意有可能会在你的垃圾箱里,找到邮件打开里面的链接则完成显示如下图表示成功:

Snip20171003_11.png
依据刚刚验证的网站中的提示:在终端中输入:pod trunk push 描述文件名称 Snip20171003_12.png
-> TestLib (0.0.1)
    - ERROR | file patterns: The `source_files` pattern did not match any file.

[!] The spec did not pass validation, due to 1 error.

这个是在指定共享的类库时, 文件路径不对, 也就是设置 s.source_files字段时, 发生了错误, 这里的路径是相对于TestLib.podspec文件的, 如果是与TestLib.podspec同级的文件夹, 直接写文件夹名称即可, 如:

s.source_files = "TestLib"

如果有多级目录, 一定要逐级添加. 这里也可以这么写:

s.source_files = "TestLib/*.{h,m}"

需要注意的是s.source_files参数,如果配置为s.source_files = '/*.{h,m}’,会报错:

- ERROR | File Patterns: File patterns must be relative and cannot start with a slash (source_files).

其它可能的报错:

 - ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

可参考 cocoapods Error

上一篇 下一篇

猜你喜欢

热点阅读