建立私有Pod

1、建立本身的 github 倉庫html

2.ios

如圖所示,咱們在 github 上建立一個空的倉庫,命名爲 initiallPod ,這個倉庫是用來存放咱們本身全部的私有庫的 spec 文件,就如同官方的 https://github.com/CocoaPods/Specsgit

而後咱們就能夠執行:github

pod repo add initiallPod https://github.com/xuanInitial/initiallPod.git

initiallPod 私有 repo 的名稱 後面是倉庫的 git 地址swift

3.查看是否建立成功app

4.打開隱藏目錄,可使用命令:ide

//打開隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
//關閉隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false

接着須要重啓一下 Finder, 能夠按住 option + 右鍵 Finder 圖標選擇重啓。工具

若是已經打開忽略這一步ui

5.而後打開隱藏目錄 .cocoapods (這個目錄在你的我的目錄底下, ~/.cocoapods 或 /Users/[你本身的用戶名]/.cocoapods)
this

以上操做 是在本地建了一個私有倉庫

2、建立靜態庫

基於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.
                       DESC

  s.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了

3、添加私有的 Repo 安裝到你的 CocoaPods 中

  1. cd xxx #你對應的項目文件夾
  2. 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
    驗證經過
  3. 而後 添加你的 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倉庫裏面有了你的最新上傳

4、使用方法

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
相關文章
相關標籤/搜索