构建本地Pod库流程网上一搜一大堆就不再重复了。
主要的坑在是配置podspec文件。
Pod::Spec.new do |s|
s.name = "ProtocolBuffNetWorking"
s.version = "0.0.1"
s.summary = "Tool for networking, base on ProtocolBuff."
s.description = <<-DESC
Tool for networking, base on ProtocolBuff.
DESC
s.homepage = "http://ProtocolBuffNetWorking"
s.license = "MIT"
s.author = { "yyf" => "765936789@qq.com" }
s.platform = :ios, "9.0"
s.source = { :git => "http://ProtocolBuffNetWorking.git", :tag => "#{s.version}" }
s.source_files = "ProtocolBuffNetWorking/ProtocolBufferModels/*.{h,m}", "ProtocolBuffNetWorking/NetWorkManager/*.{h,m,mm}","ProtocolBuffNetWorking/ProtocolBuffRequest/*.{h,m}","ProtocolBuffNetWorking/StaticLib/*.h"
s.dependency 'Protobuf','~> 3.5.0'
s.requires_arc = true
s.vendored_libraries = 'ProtocolBuffNetWorking/StaticLib/*.a'
s.libraries = 'c++.1'
non_arc_files = "ProtocolBuffNetWorking/ProtocolBufferModels/*.{h,m}"
s.exclude_files = non_arc_files
s.subspec 'no-arc' do |sp|
sp.requires_arc = false
sp.source_files = non_arc_files
end
end
自己用,描述啊,网址那些可以随便写。
出现的问题及解决
1、
'UIKit/UIKit.h' file not found
漏掉了下面这句
s.platform = :ios, "9.0"
未指定iOS系统,所以找不到UIKit。
2、依赖第三方库Protobuf
s.dependency 'Protobuf','~> 3.5.0'
3、部分代码需要支持MRC
non_arc_files = "ProtocolBuffNetWorking/ProtocolBufferModels/*.{h,m}"
s.exclude_files = non_arc_files
s.subspec 'no-arc' do |sp|
sp.requires_arc = false
sp.source_files = non_arc_files
end
4、引用自己的framework或.a文件
s.vendored_libraries = 'ProtocolBuffNetWorking/StaticLib/*.a'
s.vendored_frameworks = 'xxx/**/*.framework'
5、x86_64的错误,使用了未定义的c++函数。这是因为.a库是c++写的,需要添加系统的依赖库libc++.1.tdb。
s.libraries = 'c++.1'
6、图片资源
s.resource_bundles = {
'LazyTableViewModel' => ['Assets/*.png']
}
如果直接使用
[UIImage imageNamed:@“图片名"]
图片无法显示,这种方式默认是从mainBundle中去加载图片,会找不到图片。
可以通过路径来加载
NSBundle *bundle = [NSBundle bundleForClass:[LazyTableViewModel class]];
NSString *path = [bundle pathForResource:@"网络错误.png" ofType:nil inDirectory:@"LazyTableViewModel.bundle"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
本地库的使用
Podfile
target 'ProtocolBuffNetWorking' do
pod 'ProtocolBuffNetWorking', :path => '/路径/'
end
cd 到工程目录下
pod install