環(huán)境準備
- 安裝Xcode
- 安裝cocoapods
公共Specs
使用cocoapods滚躯,如果不指定倉庫來源的話,默認為公共Specs:https://github.com/CocoaPods/Specs.git
如果 pod install 太慢可以指定來源為cocoapods在gitee的鏡像:https://gitee.com/mirrors/CocoaPods-Specs.git
在Podfile上面添加指定來源:
source 'https://gitee.com/mirrors/CocoaPods-Specs.git'
創(chuàng)建個人specs遠程倉庫
在gitee上創(chuàng)建一個帶有Readme 文件
的倉庫柳畔,命名為CSPublicSpecs
(名稱自己決定)
PS:這里不能創(chuàng)建空倉庫馍管,否則會導(dǎo)致無法推送podspec
添加創(chuàng)建好的specs到本地:
pod repo add CSPublicSpecs https://gitee.com/hcsaaron/cspublic-specs.git
添加成功后,可以在本地~/.cocoapods/repos
下看到CSPublicSpecs
新建本地倉庫
用 默認模板 創(chuàng)建
pod lib create CSPublicSDK
指定模板創(chuàng)建
pod lib create CSPublicSDK --template-url=https://gitee.com/Pods-Lib/pod-template.git
等待下載模板完成后薪韩,按步驟選擇類型
基于已有的本地倉庫
- cd到xxx.xcodeproj工程目錄下
- 執(zhí)行
pod spec create xxx
生成xxx.podspec
文件确沸,修改相關(guān)配置 - 執(zhí)行
pod init
生成Podfile
文件,添加依賴 - 執(zhí)行
pod install
生成. xcworkspace
編輯.podspec
根據(jù)自己項目情況修改.podspec
文件俘陷,關(guān)于Podspec的學(xué)習(xí)罗捎,請看 CocoaPods - Podspec Syntax Reference
Pod::Spec.new do |s|
s.name = 'CSPublicSDK'
s.version = '0.1.0'
s.summary = 'A short description of CSPublicSDK.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://gitee.com/hcsaaron/cspublic-sdk'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'hcsaaron@163.com' => 'hcsaaron@163.com' }
s.source = { :git => 'https://gitee.com/hcsaaron/cspublic-sdk.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.source_files = 'CSPublicSDK/Classes/**/*'
# s.resource_bundles = {
# 'CSPublicSDK' => ['CSPublicSDK/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
創(chuàng)建遠程倉庫
在gitee上創(chuàng)建一個名為CSPublicSDK
的倉庫(名稱自己決定)
創(chuàng)建完成后復(fù)制git地址為:https://gitee.com/hcsaaron/cspublic-sdk.git
將本地倉庫關(guān)聯(lián)遠程倉庫:
git remote add origin https://gitee.com/hcsaaron/cspublic-sdk.git
將所有文件暫存:
git add .
提交:
git commit -m "初次提交"
推送到遠程倉庫:
git push -u origin master
推送成功:
Enumerating objects: 79, done.
Counting objects: 100% (79/79), done.
Delta compression using up to 16 threads
Compressing objects: 100% (70/70), done.
Writing objects: 100% (79/79), 27.92 KiB | 5.58 MiB/s, done.
Total 79 (delta 17), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/hcsaaron/cspublic-sdk.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
打開https://gitee.com/hcsaaron/cspublic-sdk可以看到遠程倉庫已經(jīng)更新了
驗證.podspec文件
cd到xxx.podspec
文件所在目錄下:
pod lib lint
驗證失敗,報錯:
[!] CSPublicSDK did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
You can use the `--no-clean` option to inspect any issue.
則按提示添加--allow-warnings
參數(shù):
pod lib lint --allow-warnings
看到以下提示拉盾,則說明驗證成功:
CSPublicSDK passed validation.
如果
pod lib lint
驗證失敗桨菜,可以視情況附加以下參數(shù):
--verbose
:查看詳細信息
--allow-warnings
:允許警告,用到第三方框架時捉偏,用這個參數(shù)可以屏蔽警告
--use-libraries
:如果用到的第三方庫需要使用庫文件的話倒得,會用到這個參數(shù)
--sources
:如果一個庫的podspec包含除了cocoapods倉庫以外的其他庫的引用,則需要改參數(shù)指明告私,用逗號分隔屎暇。例如:pod lib lint --sources='https://gitee.com/hcsaaron/cspublic-sdk.git'
還有另外兩個參數(shù)可以使用:
--fail-fast
:在出現(xiàn)第一個錯誤時就停止
--subspec=Name
:用來校驗?zāi)硞€子模塊的情況
發(fā)布podspec
打tag并push到遠程(tag版本號要和podspec中的s.version
一致):
git tag '0.1.0'
git push --tags
將CSPublicSDK.podspec
提交到CSPublicSpec
中:
pod repo push CSPublicSpecs CSPublicSDK.podspec
如果報錯,則添加--allow-warnings
參數(shù):
pod repo push CSPublicSpecs CSPublicSDK.podspec --allow-warnings
推送成功后驻粟,可以看到CSPublicSpecs
已經(jīng)有對應(yīng)的.podspec
了
搜索一下自己剛剛發(fā)布的pod庫:
pod search CSPublicSDK
已經(jīng)可以搜出來了
集成SDK
新建demo工程:
cd進demo工程目錄根悼,執(zhí)行pod init
生成Podfile
:
pod init
編輯Podfile
添加pod 'CSPublicSDK', '~> 0.1.0'
,還需指定來源source 'https://gitee.com/hcsaaron/cspublic-specs.git'
:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://gitee.com/hcsaaron/cspublic-specs.git'
target 'CSDemo' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for CSDemo
pod 'CSPublicSDK', '~> 0.1.0'
end
然后執(zhí)行pod install
生成.xcworkspace
pod install
已經(jīng)可以愉快地使用了