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