CocoaPods 私有化Podspec

一、主要流程

  • 1、創(chuàng)建并設(shè)置一個本地私有的Spec Repo,綁定遠(yuǎn)程Spec倉庫
  • 2、創(chuàng)建一個本地Pod庫MGAPIClient,綁定遠(yuǎn)程Pod庫
  • 3、修改podspec文件,并驗證可用性
  • 4、podspec驗證通過后,本地測試使用MGAPIClient.podspec文件
  • 5、向遠(yuǎn)程私有的Spec Repo中提交podspec
  • 6、完畢,使用制作成功的私有庫MGAPIClient了。

二、傻瓜式教學(xué)

1、創(chuàng)建一個本地私有的Spec Repo:MGSpec,綁定托管到遠(yuǎn)程倉庫
  • 1、使用bitbucket托管服務(wù),創(chuàng)建遠(yuǎn)程MGSpec倉庫
    Snip20171213_4.png
  • 2、創(chuàng)建本地私有Spec Repo,綁定托管到遠(yuǎn)程MGSpec倉庫
1. 打開命令行終端,輸入如下命令:
 
pod repo add  MGSpec https://jennyCjp@bitbucket.org/jennyCjp/mgspecs.git

2.  ~/.cocoapods/repos目錄下就可以看到 MGSpec
Snip20171213_5.png
2、創(chuàng)建遠(yuǎn)程倉庫MGAPIClient,創(chuàng)建本地Pod的項目工程庫,如:MGAPIClient ,利用命令行將本地項目托管到遠(yuǎn)程倉庫MGAPIClient
    1. 使用bitbucket托管服務(wù),創(chuàng)建遠(yuǎn)程Pod私有倉庫


      Snip20171213_19.png
    1. 創(chuàng)建Pod的項目工程庫


      Snip20171213_6.png
    1. 添加自定義類APIClient,放入MGAPIClient/MGAPIClient/Classes/
import UIKit
public class APIClient: NSObject {
   public class func requestAPI(){
        print("APIClient  requestAPI 網(wǎng)絡(luò)請求 !")
    }
}

Snip20171213_20.png
Snip20171213_21.png
# 1. 終端進(jìn)入MGAPIClient根目錄下的Example目錄中
cd /Users/asahanayuujuu/MGAPIClient/Example 

# 2. 執(zhí)行pod update 后查看項目
pod update
Snip20171213_22.png
    1. 添加提交, 并打tag0.1.0后 ,推送到剛才創(chuàng)建的遠(yuǎn)程MGAPIClient倉庫
Snip20171213_28.png
# 終端進(jìn)入MGAPIClient根目錄下
cd /Users/asahanayuujuu/MGAPIClient

# 添加,提交本地倉庫,并推送到遠(yuǎn)程倉庫MGAPIClient
git add .
git commit -s -m "初始化MGAPIClient庫"
git remote add origin git@bitbucket.org:jennyCjp/mgapiclient.git
git push -u origin master

# podspec文件中獲取Git版本控制的項目需要tag號,要打tag
 git tag -m '初始化 release' 0.1.0
 git push --tags   #推送tag到遠(yuǎn)程倉庫
    1. 查看遠(yuǎn)程MGAPIClient源碼,已經(jīng)將本地倉庫,推送到遠(yuǎn)程


      Snip20171213_29.png
3、修改本地pod庫MGAPIClient中的podspec文件,并驗證可用性,驗證通過后,將本地Pod庫推送到遠(yuǎn)程
  • 1、配置podspec文件

    Pod::Spec.new do |s|
    s.name             = 'MGAPIClient'
    s.version          = '0.1.0'   #版本號 要與剛才提交到遠(yuǎn)程倉庫MGAPIClient打的tag標(biāo)識一致。
    s.summary          = 'MGAPIClient 封裝了一個網(wǎng)絡(luò)框架,便于以后快速集成開發(fā).'
    
    s.description      = <<-DESC
               MGAPIClient 是 測試Pod的一個Demo,封裝了一個網(wǎng)絡(luò)框架,便于以后快速集成開發(fā)。
                        DESC
    # 主頁,填寫可以訪問到的地址,否則驗證不通過
    s.homepage         = 'https://jennyCjp@bitbucket.org/jennyCjp'
    # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
    
    # 開源協(xié)議
    s.license          = { :type => 'MIT', :file => 'LICENSE' }
    s.author           = { 'jennyCheng' => '2271648527@qq.com' }
    
    # Pod庫遠(yuǎn)程地址,不支持ssh,請使用Https
    s.source           = { :git => 'https://jennyCjp@bitbucket.org/jennyCjp/mgapiclient.git', :tag => s.version.to_s }
    # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
    
    # 持的平臺及版本
    s.ios.deployment_target = '8.0'
    
    # 源代碼文件地址,**/*表示Classes目錄及其子目錄下所有文件
    # 如果有多個目錄下則用逗號分開,如果需要在項目中分組顯示,這里也要做相應(yīng)的設(shè)置
    s.source_files = 'MGAPIClient/Classes/**/*'
    
    # 資源文件地址
    # s.resource_bundles = {
    #   'MGAPIClient' => ['MGAPIClient/Assets/*.png']
    # }
    
    
    #公開頭文件地址
    # s.public_header_files = 'Pod/Classes/**/*.h'
    
    #所需的framework,多個用逗號隔開
    # s.frameworks = 'UIKit', 'MapKit'
    
    #依賴庫,該項目所依賴的其他庫,如果有多個需要填寫多個s.dependency
    # s.dependency 'AFNetworking', '~> 2.3'
    end
    
    1. 驗證
# 進(jìn)入本地MGAPIClient根目錄
cd /Users/asahanayuujuu/MGAPIClient
# 驗證,
pod lib lint
# 如下則驗證通過后,podspec就是一個符合CocoaPods規(guī)則的配置文件了。
 -> MGAPIClient (0.1.0)
MGAPIClient passed validation.

# 推送到遠(yuǎn)程MGAPIClient倉庫

可能警告錯誤:

1、 驗證podspec文件時

-> MGAPIClient (0.1.0)
    - WARN  | [iOS] swift_version: 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`
  • 解決方式:
 終端執(zhí)行 echo 3.0 > .swift-version
 后執(zhí)行驗證  pod lib lint
4、podspec驗證通過后,本地測試MGAPIClient項目中的MGAPIClient.podspec使用
    1. 修改MGAPIClient中的Podfile文件

Podfile原文件

use_frameworks!
target 'MGAPIClient_Tests' do  
 pod 'MGAPIClient', :path => '../'
end

修改成

use_frameworks!
target 'MGAPIClient_Tests' do
  # pod 'MGAPIClient', :path => '../'
  pod 'MGAPIClient', :podspec => '../MGAPIClient.podspec'
end
    1. 更新pod庫
# 進(jìn)入本地MGAPIClient根目錄Example文件
cd /Users/asahanayuujuu/MGAPIClient/Example
# 執(zhí)行更新
pod update

在之前pod update前與后,文件對比


更新前.png
更新后.png
5、向遠(yuǎn)程私有的Spec Repo中提交podspec
  • 1、提交推送本地MGAPIClient庫修改,到遠(yuǎn)程MGAPIClient倉庫
# 進(jìn)入本地MGAPIClient根目錄
cd /Users/asahanayuujuu/MGAPIClient
git add .
git commit -s -m "podspec文件測試修改"
git push origin master #提交到遠(yuǎn)程倉庫
  • 2、推送MGAPIClient.podspec到私有遠(yuǎn)程spec倉庫
# 進(jìn)入本地MGAPIClient根目錄
cd /Users/asahanayuujuu/MGAPIClient

# podspec文件推送到私有遠(yuǎn)程spec倉庫
# 注意:MGSpec:之前本地創(chuàng)建的spec名字, MGAPIClient.podspec: 創(chuàng)建本地pod項目中的podspec名字。
pod repo push MGSpec MGAPIClient.podspec 
    1. 成功推送
Validating spec
 -> MGAPIClient (0.1.0)

Updating the `MGSpec' repo

Already up-to-date.

Adding the spec to the `MGSpec' repo

 - [Add] MGAPIClient (0.1.0)

Pushing the `MGSpec' repo
    1. 對比之下推送podspec文件到遠(yuǎn)程spec倉庫的前與后:


      前.png
后.png
    1. 查看遠(yuǎn)程Spec倉庫,查看推送podspec文件后。


      推送podspec文件后.png
6、完畢,使用制作成功的私有庫MGAPIClient
  • 1、新建iOS項目tesstPod,創(chuàng)建profile文件,添加MGAPIClient倉庫
# 私有Spec Repo
source 'https://git.coding.net/kensla/DDSpecs.git' 
pod 'MyLib', '~> 0.1.0'
Snip20171213_38.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容