现象描述:在使用cocoaPods制作私有库时,在私有库里,需要导入之前自己制作的 framework;导入之后,编译正常;但是运行报错:unrecognized selector sent to class XXX 。
原因分析:运行正常,说明头文件导入正确;但是运行报错,结合报错信息可知,是二进制文件没有实际导入;这种情况,需要确认:1,导入的framework,是否正确实现了方法; 2,导入的 framework 是否正确使用了标志位;此处,我的错误为第二种; framework 导入时,没有在工程中的 other linker flags 中添加标志位:-ObjC; (-ObjC: 链接库中的所有oc代码到app;此外,还有 -all_load: 链接库中所有代码到 app ; 等,参考链接:点击打开链接);
解决方案:1,可以直接修改pod 工程下的 对应组件的 target 中的 other linker flags ,添加 -ObjC 标志位;2,修改podSpec 文件,动态添加标志位; 此处:我采用的第二种,在 podSpec 文件中,添加:
s.xcconfig = { "OTHER_LDFLAGS" => "-ObjC" }
ps:在导入EVERUIKit.framwork (自己制作的库的名字) 后,pod 中的其他文件使用时,直接
#import "EVERUIKit/EVERUIKit.h"
即可:
附podSpec文件一份,以作参考
#
# Be sure to run `pod lib lint TEST.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'TEST'
s.version = '0.0.1'
s.summary = 'A short description of TEST.'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://gitee.com/jiajiayouba/TEST'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Ever' => 'wangyongbao2009@hotmail.com' }
s.source = { :git => 'https://gitee.com/jiajiayouba/TEST.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'TEST/Classes/**/*'
# s.resource_bundles = {
# 'TEST' => ['TEST/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.vendored_frameworks = 'TEST/Frameworks/*.framework'
s.xcconfig = { "OTHER_LDFLAGS" => "-ObjC" }
end