pod命令創建私有庫詳解【引用其他私有庫、oc、Swift混編】


1、命令創建pod

pod lib create pod的名字

2、根據指令依次填寫信息

3、填寫完成后會自動打開項目 、然后修改podspec文件即可

4、創建當前pod的git 倉庫、將當前代碼放入倉庫 並打上和spec中version 對應的tag

git remote add origin 倉庫地址
git add .
git commit -m "install commit"
git push -u origin master
git tag 0.1.0
git push --tags

4、創建一個pod 索引的git倉庫

將索引倉庫添加到本地

pod repo add demoSpecs git地址

4、檢測一下當前編寫的sepc 並提交到索引庫 

pod lib lint 本地檢測
pod spec lint 遠端檢測
pod repo push demoSpecs testPod.podspec

5、遠端索引庫里面已經有了當前的0.1.0的 testPod了 然后在項目中使用編寫 podfile 

source  'https://github.com/CocoaPods/Specs.git'
source   索引庫地址
use_frameworks!

platform :ios, '9.0'

target 'testPod_Example' do
  pod 'testPod'

end

5、如果pod中使用了到了自己的私有庫 校驗的時候 需要加上校驗sources路徑 多個私有庫 , 隔開就好

pod spec lint testPod.podspec  --use-libraries --allow-warnings --sources='私有庫地址.git','https://github.com/CocoaPods/Specs.git'

6、如果pod倉庫是oc、Swift混編

需要創建一個public_header的oc文件 在里面添加項目需要共同訪問的頭文件 這和項目的橋接文件功能一樣 然后podspec中設置公開文件為當前文件   ** ** 注意橋接文件一定要是oc並且是繼承於NSObject

   

7、pod項目中如果要使用其他的pod文件 但當前pod又沒對其添加依賴 值需要配置 FRAMEWORK_SEARCH_PATHS 例如 pod中想使用 MBProgressHUD  

  search_paths = [
    #Podfile使用指定路徑鏈接
    '${PODS_CONFIGURATION_BUILD_DIR}/podChatLibrary',
    '${PODS_CONFIGURATION_BUILD_DIR}/MBProgressHUD'
    ]
    s.pod_target_xcconfig = {
      'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
      'FRAMEWORK_SEARCH_PATHS' => search_paths,
    }

8、pod中如果要使用.xcassets  

podspec中添加    s.resource_bundle = { 'test' => ['testPod/Assets/**.xcassets'] }

代碼里面獲取圖片如下

func getImage(_ imageName: String) -> UIImage? {
    // test 為pod 中resourcebundle中設置的名字
    let imageBundleURL = Bundle.main.url(forResource: "test", withExtension: "bundle")
    let imgBundle = Bundle(url: imageBundleURL!)
    let img = UIImage(named: imageName, in: imgBundle, compatibleWith: nil)
    return img
}

 9、依賴其他庫如果 執行報錯

The ‘Pods-XXX‘ target has transitive dependencies that include statically linked binaries:
(/Users/XXXX/XXXX/XXXX/XXXX.framework)

在podfile最后加入下面的代碼

pre_install do |installer|
  # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM