1.pod lib lintpod spec lint 命令的区别

  • pod lib lint是只从本地验证你的pod能否通过验证;
  • pod spec lint是从本地和远程验证你的pod能否通过验证;

2.私有pod的验证

使用pod spec lint去验证私有库能否通过验证时应该要添加--sources选项,不然会出现找不到repo的错误:

1
pod spec lint --sources='私有仓库repo地址,https://github.com/CocoaPods/Specs'

3.subspec

为了让自己的Pod被导入时显示出良好的文件层划分,subspec是必须的。
subspec要依赖其它的subspec,则subspecdependency后面接的不是目录路径,而是specA/specB这种spec关系;

4.私有库引用私有库的问题

在私有库引用了私有库的情况下,在验证和推送私有库的情况下都要加上所有的资源地址,不然Pod会默认从官方repo查询。

1
2
pod spec lint --sources='私有仓库repo地址,https://github.com/CocoaPods/Specs'
pod repo push 本地repo名 podspec名 --sources='私有仓库repo地址,https://github.com/CocoaPods/Specs

5.引用自己或第三方的framework.a文件时

podsepc中应该这样写:

1
2
s.ios.vendored_frameworks = "xxx/**/*.framework"
s.ios.vendored_libraries = "xxx/**/*.a”

6.引用静态库:(.ios).library。去掉头尾的lib,用”,”分割

1
2
// 引用libxml2.lib和libz.lib.
spec.libraries = 'xml2', 'z'

7.引用公有framework:(.ios).framework. 用”,”分割. 去掉尾部的”.framework

1
spec.frameworks = 'UIKit','SystemConfiguration', 'Accelerate'

8.引用自己生成的framework:(.ios).vendored_frameworks。用”,”分割,路径写从.podspec所在目录为根目录的相对路径 ps:这个不要省略.framework

1
spec.ios.vendored_frameworks = 'Pod/Assets/*.framework'

9.引用自己生成的.a文件, 添加到Pod/Assets文件夹里. Demo的Example文件夹里也需要添加一下, 不然找不到

1
spec.ios.vendored_libraries = 'Pod/Assets/*.a'

在提交到私有仓库的时候需要加上--use-libraries

10.私有库中添加资源(图片、音视频等)

方法共有三种:

  • 第一种
1
spec.resources = ["Images/*.png", "Sounds/*"]

但是这些资源会在打包的时候直接拷贝的AppBundle中,这样说不定会和其它资源产生命名冲突;

  • 第二种
1
spec.resource = "Resources/MyLibrary.bundle"

把资源都放在bundle中,然后打包时候这个bundle会直接拷贝进AppmainBundle中。使用的时候在mainBundle中查找这个bundle然后再搜索具体资源:

1
2
3
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"MyLibrary" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
UIImage *imgage = [UIImage imageNamed:icon inBundle:bundle compatibleWithTraitCollection:nil];
  • 第三种
1
2
3
4
spec.resource_bundles = {
'MyLibrary' => ['Resources/*.png'],
'OtherResources' => ['OtherResources/*.png']
}

这种方法利用framework的命名空间,有效防止了资源冲突。
使用方法是先拿到最外面的bundle,然后再去找下面指定名字的bundle 对象,再搜索具体资源:

1
2
3
4
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSURL *bundleURL = [bundle URLForResource:@"MyLibrary" withExtension:@"bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithURL: bundleURL];
UIImage *imgage = [UIImage imageNamed:icon inBundle:resourceBundle compatibleWithTraitCollection:nil];

11.如果私有库添加了静态库或者dependency用了静态库

那么执行pod lib lint还有pod spec lint时候需要加上—user-libraries选项,否则会出现'The 'Pods' target has transitive dependencies错误

12.如果私有库只引用其他库的subspec

只需要依赖想依赖的subspec,不用管主spec(因为依赖subspec必然要依赖主spec

13.私有库已经通过验证并传到私有repo也能通过pod search,但是就是pod install失败

这时候只要执行pod update

14.提交到私有仓库的之前可以先验证一下, 有问题就修复它, 验证过了在提交

1
pod spec lint VenderName.podspec --verbose

打好tag, 推到Git里去后, 才可以在测试的项目里的Podfile里引用这个库, 然后pod update VenderName --no-repo-update, 测试通过了, 在提交到私有仓库里

1
pod 'VenderName', :podspec => 'VenderName.podspec的路径地址'

还可以指定引用某个分支的代码

1
pod 'VenderName', :git => 'https://git.coding.net/CodingZero/VenderName.git', :branch => 'develop'

提交到私有仓库的时候还可以忽略警告类的错误, 愣是要提交. 在后面加上--allow-warnings

1
pod repo push LYSpecs VenderName.podspec --allow-warnings

如果有添加新的文件, 需要更新下引索, Demo里才可以识别

1
pod update VenderName --no-repo-update

15.使用的时候还可以通过直接指定地址 + tag or 分支 or commit 的方式来引入, 这样就可以不用走发布流程了. 也不需要添加源了.

1
2
3
4
5
pod 'VenderName', :git => 'https://git.coding.net/CodingZero/VenderName.git', :tag => '0.8.1'

pod 'VenderName', :git => 'https://git.coding.net/CodingZero/VenderName.git', :branch => 'develop'

pod 'VenderName', :git => 'https://git.coding.net/CodingZero/VenderName.git', :commit => '0812fe81319af2411233'