【iOS】將程式碼上傳到pod創庫
- 2020 年 3 月 30 日
- 筆記
1、利用pod創建項目
pod lib create PPKit
這時候的生成工程目錄為

編寫podspec文件
# # Be sure to run `pod lib lint PPKit.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 https://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| s.name = 'PPKit' s.version = '0.0.1' s.summary = 'A short description of PPKit.' # 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. DESC s.homepage = 'https://github.com/maple1994/PPKit' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'maple1994' => '[email protected]' } s.source = { :git => 'https://github.com/maple1994/PPKit.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' s.ios.deployment_target = '8.0' s.source_files = 'PPKit/Classes/**/*' # s.resource_bundles = { # 'PPKit' => ['PPKit/Assets/*.png'] # } # s.public_header_files = 'Pod/Classes/**/*.h' # s.frameworks = 'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' end
可以看到我們指定source_files指定在PPKit/Classes文件夾下的所有文件,所以我們的源碼都放在這裡就可以了
2、上傳程式碼到pod
podspec文件編輯好後,我們就可以上傳該文件到pod上了,進入podspec同級目
pod trunk push
如果之前沒有註冊pod帳號的,先註冊/登錄也是執行以下指令
pod trunk register [email protected] 'maple'
3、私有庫
私有庫跟公有庫最大的區別就是,podspec的文件擺放位置。如果podspec文件都上傳到github上的 https://github.com/CocoaPods/Specs,所以如果我們想搭建私有庫,我們也要在自己的倉庫搭建一個專門存放specs文件的地方。那麼我們上傳spec文件的時候,就要添加倉庫和推送指定的倉庫
// 添加 pod repo repoName [email protected]:iOSPods // 推送 pod repo push repoName xxx.podspec
更詳細的內容可以參考 http://www.cocoachina.com/articles/26210