創建私有Private Pods 筆記
創建私有 spec repo:
pod add repo ‘MySpecs’ ‘specs repo url’創建私有庫,并創建 pod 同名 .spec 文件
執行 pod lib lint 本地驗證,pod spec lint 遠程驗證添加私有庫到私有 specs
pod repo push MySpecs 私有庫.podspec
Eg: pod repo push Specs BTCacheKit.podspec私有庫依賴私有庫
在 podfile 頂部添加 source
source ‘MySpecs url link’
source 'https://github.com/CocoaPods/Specs.git'
之后 podfile 以及 s.dependency 中都是正常引用就可以校驗當前私有庫;本地校驗執行的 pod lib lint 需要添加sources 如:pod lib lint —sources=‘MySpecs url link’如果,sources 是多個,中間用逗號隔開即可;出現警告:--allow-warnings 進行排除;(pod lib lint --sources="私有庫鏈接,https://github.com/CocoaPods/Specs.git")
遠程校驗 pod spec lint --allow-warnings
出現警告
[!] The repo
Specs
at../../../../../.cocoapods/repos/Specs
is not clean
cd ../../../../../.cocoapods/repos/Specs
git clean -f
問題:
pod repo中明明存在的podspec 卻search 不到
指定--sources: pod lib lint --sources="自己私有的pod,https://github.com/CocoaPods/Specs.git"
私有庫中添加圖片/音頻資源
第一種
spec.resources = ["Images/.png", "Sounds/"]
但是這些資源會在打包的時候直接拷貝的app的Bundle中,這樣說不定會和其它資源產生命名沖突
第二種
spec.resource = "Resources/MYLibrary.bundle"
把資源都放在bundle中,然后打包時候這個bundle會直接拷貝進app的mainBundle中。使用的時候在mainBundle中查找這個bundle然后再搜索具體資源
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"JZShare" withExtension:@"bundle"]; NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; UIImage *img = [UIImage imageNamed:icon inBundle:bundle compatibleWithTraitCollection:nil];
第三種
spec.resource_bundles = {
'MyLibrary' => ['Resources/.png'],
'OtherResources' => ['OtherResources/.png']
}
這種方法利用 framework 的命名空間,有效防止了資源沖突。
使用方法是先拿到最外面的 bundle,然后再去找下面指定名字 的 bundle 對象,再搜索具體資源
NSBundle *bundle = [NSBundle bundleForClass:[MYSomeClass class]]; NSURL *bundleURL = [bundle URLForResource:@"MyLibrary" withExtension:@"bundle"]; NSBundle *resourceBundle = [NSBundle bundleWithURL: bundleURL]; UIImage *img = [UIImage imageNamed:icon inBundle:bundle compatibleWithTraitCollection:nil];
問題:include of non-modular header inside framework module”
spec.user_target_xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' }
拉取遠程的分支:
git remote add origin xxxxx
出現沖突的話
git pull origin master --allow-unrelated-histories
官方文檔
https://guides.cocoapods.org/making/private-cocoapods.html
https://guides.cocoapods.org/syntax/podspec.html