Latest 0.2.1
Homepage https://github.com/yangbryant/CocoaPods_framework_tutorial
License MIT
Platforms ios 8.0
Frameworks UIKit
Authors

通过CocoaPods方式打包framework

通过pod lib命令创建项目

  • pod lib create project-name 创建项目.
pod lib create SLDate

1_pod_lib_create

  • 创建后打开工程,看一下工程文件.

2_project_structure

把你想要打包的文件放到路径下

  • 框架的源码文件放到 Classes 下,路径千万别搞错.
  • 图片资源文件放到 Assets 下,需要在 s.resource 额外添加.

3_file_structure

编辑 *.podspec 文件

Pod::Spec.new do |s|
  s.name             = 'SLDate'
  s.version          = '0.2.0'
  s.summary          = 'SLDate is a NSDate Category.'

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/yangbryant/CocoaPods_framework_tutorial'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Srefan' => '[email protected]' }
  s.source           = { :git => '/Users/zhengxin/gitlab/Others/CocoaPods_framework_tutorial', :tag => s.version.to_s }

  s.ios.deployment_target = '8.0'

  s.source_files = 'SLDate/Classes/*.{h,m}'

  s.resource_bundles = {
    'SLDate' => ['SLDate/Assets/*.png']
  }

  # 只开放SLCategory头文件,隐藏SLBase头文件
  s.public_header_files = 'SLDate/Classes/NSDate+SLCategory.h'
  s.frameworks = 'UIKit'

  # 如果你的库使用了其他第三方库,需要加入
  # s.dependency 'AFNetworking', '~> 2.3'
end

Lint PodSpec文件的规则

pod lib lint SLDate.podspec --allow-warnings
  • --allow-warnings 忽略警告信息

--only-errors--allow-warnings区别
--allow-warnings是允许warning的存在, 也就是说当你在pod lib lint验证podspec的时候, 有警告也能验证通过.
--only-errors是只显示出错误, 就是你在验证的时候就算--allow-warnings, 但是那些warnings也还是会打印出来和errors混杂在一起, 这会让你很难找error. 所以这里使用--only-errors来只打印error,不打印warning.

  • --use-libraries 针对引用依赖了第三方Pod库

4_pod_lib_lint

导入文件到项目内

  • 切换到 Example 路径下,执行 update 操作.
cd Example
pod update --verbose --no-repo-update

5_pod_update

  • 更新后再看一下工程文件.

6_updated_project_strcture

本地提交代码

# 提交代码
git commit -m "v0.1.0"
# 创建tag
git tag -a 0.1.0 -m "v0.1.0"

打包framework

打包需要使用 CocoaPodspackage插件, 安装方法.

pod package SLDate.podspec --force # 打包成framework
  • pod package SLDate.podspec --library --force 打包成 .a 文件.

7_pod_package

生成framework外链

  • 压缩framework成zip包, 上传生成外链.

8_create_framework_url

编辑 *.PodSpec 文件

  • 注意: 此podspec文件是打包后的podspec文件,不是创建项目的那个.
Pod::Spec.new do |s|
  s.name = "SLDate"
  s.version = "0.2.0"
  s.summary = "SLDate is a NSDate Category."
  s.license = {"type"=>"MIT", "file"=>"LICENSE"}
  s.authors = {"Srefan"=>"[email protected]"}
  s.homepage = "https://github.com/yangbryant/CocoaPods_framework_tutorial"
  s.description = "TODO: Add long description of the pod here."
  s.frameworks = "UIKit"
  s.source = { :http => 'https://github.com/yangbryant/CocoaPods_framework_tutorial/releases/download/0.2.0/SLDate.zip' }
  s.platform = :ios

  s.ios.deployment_target    = '8.0'
  s.ios.vendored_framework   = 'SLDate.framework'
end

Lint PodSpec文件的规则

  • 同样要 Lint 下规则, 还是打包后的文件.
cd SLDate-0.2.0/
pod spec lint SLDate.podspec --allow-warnings

pod spec 相对于 pod lib 会更为精确, pod lib 相当于只验证一个本地仓库, pod spec 会同时验证本地仓库和远程仓库.

提交到 Pod

pod trunk push --allow-warnings

9_pod_trunk_push

搜索我的库

pod search SLDate

10_pod_search

创建Demo项目,用Pod导入库

  • pod init创建 PodFile文件
# Uncomment the next line to define a global platform for your project
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!

target 'Demo' do
pod 'SLDate'
end

11_pod_install

项目中调用

12_project_code

OK, 成功了, Finished!

License

SLDate is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SLDate",
    "version": "0.2.1",
    "summary": "SLDate is a NSDate Category.",
    "license": "MIT",
    "authors": {
        "Srefan": "[email protected]"
    },
    "homepage": "https://github.com/yangbryant/CocoaPods_framework_tutorial",
    "description": "TODO: Add long description of the pod here.",
    "frameworks": "UIKit",
    "source": {
        "http": "https://github.com/yangbryant/CocoaPods_framework_tutorial/releases/download/0.2.0/SLDate.zip"
    },
    "platforms": {
        "ios": "8.0"
    },
    "ios": {
        "vendored_frameworks": "SLDate.framework"
    }
}

Pin It on Pinterest

Share This