一、創建自己的 github 倉庫
2.
如圖所示,我們在 github 上創建一個空的倉庫,命名為 initiallPod ,這個倉庫是用來存放我們自己所有的私有庫的 spec 文件,就如同官方的 https://github.com/CocoaPods/Specs
然后我們就可以執行:
pod repo add initiallPod https://github.com/xuanInitial/initiallPod.git
initiallPod 私有 repo 的名稱 后面是倉庫的 git 地址
3.查看是否創建成功
4.打開隱藏目錄,可以使用命令:
//打開隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
//關閉隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false
接著需要重啟一下 Finder, 可以按住 option + 右鍵 Finder 圖標選擇重啟。
如果已經打開忽略這一步
5.然后打開隱藏目錄 .cocoapods (這個目錄在你的個人目錄底下, ~/.cocoapods 或 /Users/[你自己的用戶名]/.cocoapods)
以上操作 是在本地建了一個私有倉庫
二、創建靜態庫
基于pod自動創建
1.執行命令pod lib create xxx。
xxx 代碼你要生成的pod的名稱
2.打開HttpsRefreshNetWork.podspec文件,修改類庫配置信息
HttpsRefreshNetWork.podspec 找到你自己對應的文件
#
# Be sure to run `pod lib lint HttpsRefreshNetWork.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 = 'HttpsRefreshNetWork' #Pod的名字s.version = '0.1.0' #版本號s.summary = 'A short description of HttpsRefreshNetWork.'# 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
TODO: Add long description of the pod here.DESCs.homepage = 'https://github.com/yxuaninitial@163.com/HttpsRefreshNetWork' #Pod的地址# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2's.license = { :type => 'MIT', :file => 'LICENSE' }s.author = { 'yxuaninitial@163.com' => 'xuaninitial@gmail.com' } #作者s.source = { :git => '/Users/sky/Desktop/HttpsRefreshNetWork', :tag => '0.1.0' } #代碼的本地地址以及tag# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'s.ios.deployment_target = '8.0's.source_files = 'HttpsRefreshNetWork/Classes/**/*' #本地驗證這里填 "**/*" 表示當前目錄以及子目錄的所有文件 # s.resource_bundles = {# 'HttpsRefreshNetWork' => ['HttpsRefreshNetWork/Assets/*.png'] #這個是資源列表如果沒有也注釋# }# s.public_header_files = 'Pod/Classes/**/*.h' #需要對外導出的頭文件 此處為本地驗證 如果沒有對外文件需要注釋掉s.frameworks = 'UIKit', 'MapKit's.dependency 'AFNetworking'
end
3.進入Example文件夾,執行pod install,讓demo項目安裝依賴項并更新配置。
4.添加要封裝的代碼
注意:
文件存放的位置在Pod/Classes目錄下,跟podspec配置要一致。
然后
pod install
5.上傳你的項目到git
一頓亂操作 然后上傳失敗.......
找到一個好用的工具
下載地址
安裝配置過程略
以下是配置完成后
直接添加你的代碼就可以上傳到github了
三、添加私有的 Repo 安裝到你的 CocoaPods 中
cd xxx #你對應的項目文件夾
pod lib lint #本地驗證你的podspec 是否合法
報錯[!] The spec did not pass validation, due to 2 warnings (but you can use --allow-warnings to ignore them).
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a .swift-version file to set the version for your Pod. For example to use Swift 2.3, run:
echo "2.3" > .swift-version.
然后
pod lib lint --allow-warnings
驗證通過然后 添加你的 podspec 到你的 repo
pod repo push initialPod HttpsRefreshNetWork.podspec
一直不成功
Validating spec-> HttpsRefreshNetWork (0.1.0)- WARN | summary: The summary is not meaningful.- WARN | url: The URL (https://github.com/yxuaninitial@163.com/HttpsRefreshNetWork) is not reachable.
[!] The HttpsRefreshNetWork.podspec specification does not validate.
通過下面的檢查錯誤 還是第一個報錯
pod spec lint HttpsRefreshNetWork.podspec --verbose
最后解決方法
pod repo push initialPod HttpsRefreshNetWork.podspec --allow-warnings
initialPod: 你本地的倉庫名稱 HttpsRefreshNetWork.podspec:對應的podspec 文件名
--allow-warnings :忽略警告
4.再進入到 .cocoapods 的目錄中,可以看到已經發生了變化:
5.然后github倉庫里面有了你的最新上傳
四、使用方法
Podfile文件里面 添加
source 'https://github.com/xuanInitial/initialPod.git'pod 'HttpsRefreshNetWork' #請求庫
可以多個 source 并列添加
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/xuanInitial/initialPod.git'
platform :ios,'8.3'
inhibit_all_warnings!
target 'test' do
pod 'AFNetworking', '~> 3.0'
pod 'Masonry', '~> 0.6.2'
pod 'JSONModel', '~> 1.1.0'
pod 'MJRefresh'
pod 'EAIntroView', '~> 2.9.0'
pod 'PNChart'
pod 'CYLTabBarController'
pod 'MBProgressHUD', '~> 1.0.0'
pod 'FMDB'pod 'SDWebImage/WebP'pod 'HttpsRefreshNetWork'
end