cocoaPods 制作私有库,导入framework时,报错:unrecognized selector sent to class

现象描述:在使用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值