- 创建及配置方式
到远程仓库创建工程
Gitee code.aliyun Github等都可以
查看本地索引库
pod repo
添加私有索引库
pod repo add HKIJKVideo git@gitlab.ops.xxx.com:xxxx/HKIJKVideo
<li>创建组件库
使用组件库模板创建
pod lib create HKIJKVideo
添加组件内容
HKIJKVideo->Class 删掉ReplaceMe.m,添加自己的内容
修改Spec
Pod::Spec.new do |s|
s.name = 'HKIJKVideo'
s.version = '0.1.0'
s.summary = 'A short description of HKIJKVideo.'
s.description = <<-DESC
Add long description of the pod here.
DESC
s.homepage = 'git@gitlab.ops.xxx.com:xxxx/HKIJKVideo'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'lefo720' => 'xxxx@xxx.com' }
s.source = { :git => 'git@gitlab.ops.xxxx.com:xxx/hkijkvideo.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.source_files = 'HKIJKVideo/Classes/*'
s.resource_bundles = {
'HKIJKVideo' => ['HKIJKVideo/Assets/**/*']
}
s.vendored_frameworks = 'HKIJKVideo/libs/IJKMediaFramework.framework'
s.frameworks = 'UIKit', 'AudioToolbox', 'CoreAudio', 'CoreMedia', 'MediaPlayer', 'QuartzCore', 'OpenGLES', 'VideoToolbox', 'MobileCoreServices', 'CoreGraphics', 'AVFoundation'
s.dependency 'Masonry'
s.static_framework = true
校验本地
pod lib lint --allow-warnings
校验远程
pod spec lint --allow-warnings
- 使用方式
远程私有库的使用需要推送到创建的仓库中
Podfile文件顶部添加
source 'git@gitlab.ops.xxx.com:lilei1/hkijkvideo.git'(需要引用的私有库)
source 'https://github.com/CocoaPods/Specs.git'(保证公有库正常使用)
target
pod 'HKIJKVideo',:git => 'git@gitlab.ops.xxx.com:xxx/hkijkvideo.git'
@end
本地使用私有库无需推送, 直接引用,注意放在与MainProject统一目录
target
pod pod 'HKIJKVideo', :path => '../HKIJKVideo'
@end
- 常用的解决方案
1.静态库的使用方式及报错的解决方
vendored_frameworks 可以加载多个自己编译好的Framework,需要指定完整的路径
dependency 用于指定三方开源库
1.当使用多个Framwork时,遇到不可知的错误, 可以使用s.static_framework = true,但是当vendored使用了动态库除外, 因为在乙方使用的时候, pod头部添加use_frameworks!就会导致一系列错误
2.当framework中使用了动态库, 乙方在pod后,出现img not found错误为动态库无法链接. 解决方案有两种 ① 苹果推荐的方式, 在Embedded Binaries中添加需要的该库,②建立自己的publicHeader利用cocoapod将动态库和静态库拍平,乙方可以直接引入
注:①的方案需要乙方进行单独配置,推荐②方案乙方无需另外配置, 但是②中方案需要将framework包全部上传到git上 ,乙方pod时候可以完全使用cocoapod进行加载.②种方案的防线可能Framework包过大,存在上传风险
2.图片资源的加载方式
①要将图片资源放在Asset中,推荐根据不同功能封装为不同Bundle, 如果全部图片放在Asset中, 最终pod会根据组件名生成Bundle,加载图片时候需注意查找不同Bundle
②加载图片时不能使用 -(void)imageName:(NSSttring *)name ;而是使用Bundle pathxxxxx , 推荐使用宏进行批处理
3.当使用其他pod库中的静态库时, 应该这样配置
#当使用的 Framework时
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '${PODS_ROOT}/PolyvIJKPlayer' }
#当使用.a时
s.xcconfig = { 'LIBRARY_SEARCH_PATHS' => '$(PODS_ROOT)/PolyvIJKPlayer' }
4.当代码中包含xib文件时, xib文件和png同属资源文件, 可以把xib文件放入asset中, 进行加载.
网友评论