ios - 使用 'vendored_frameworks' 和 'source_files' 用于 cocoapod 使用 'use_frameworks!'

标签 ios swift frameworks cocoapods

我正在构建一个 cocoapod,它基本上包含一个框架(私有(private)资源)和一个依赖于该框架的 View (开源),所有这些都是用 Objective-C 制作的。

在 podspec 中我有以下几行:

  • spec.vendored_frameworks = 'MyPod/Framework/MyFramework.framework'
  • spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']

当使用 use_frameworks! 语法时,我不能 #import MyFramework

我只是不明白发生了什么。

此外,当我删除 spec.source_files 行时,我可以 #import MyFramework 并且它完美地工作,但当然我不能使用 MyView.

我做错了什么?

最佳答案

对于今天遇到此问题的任何人:这是 CocoaPods 中的一个已知问题,在 Github 上提出了一些问题 herehere讨论问题。

建议的解决方法是将您的 podspec 一分为二:一个 podspec 仅包含您的 vendored_frameworks,另一个 podspec 仅包含使用该框架的 source_files

Github 上的用户 crsantos 有 helpfully posted此解决方法的一个示例,我在下面复制了两个单独的 podspecs。

供应商框架 podspec:

# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409
Pod::Spec.new do |s|
  s.name             = 'SampleDynamicLibPod'
  s.version          = '0.0.1'
  s.summary          = 'SampleDynamicLibPod. Cool Story bro!'

  s.description      = <<-DESC
Blah Blah Blah Blah Blah description
                       DESC

  s.homepage         = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Carlos Santos' => 'mail@example.com' }
  s.source           = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }
  # this is the way of tagging diferent podspecs on the same repo
  # Dont't forget to tag your repo with `SampleDynamicLibPod-0.0.1` for this specific spec

  s.module_name      = 'SampleDynamicLibPod'

  s.ios.deployment_target = '9.0'
  s.platform = :ios, '9.0'
  s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }

  s.vendored_frameworks = 'SampleDynamicLibPod/Frameworks/SampleDynamicLib.framework'
end

源文件 podspec.请注意对销售框架 podspec 的依赖性。

# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409

Pod::Spec.new do |s|
  s.name             = 'WrapperAroundSampleDynamicLibPod'
  s.version          = '0.0.2' # just a different number to avoid confusion with the other podspec
  s.summary          = 'WrapperAroundSampleDynamicLibPod. Cool Story bro!'

  s.description      = <<-DESC
Wrapper Around Sample Dynamic Lib Pod Blah Blah Blah Blah Blah Blah Blah Blah
                       DESC

  s.homepage         = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Carlos Santos' => 'mail@example.com' }
  s.source           = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }

  # Dont't forget to tag your repo with `WrapperAroundSampleDynamicLibPod-0.0.2` for this specific spec

  s.module_name      = 'WrapperAroundSampleDynamicLibPod'

  s.ios.deployment_target = '9.0'
  s.platform = :ios, '9.0'
  s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }

  s.source_files = 'WrapperAroundSampleDynamicLibPod/Classes/**/*'

  s.dependency 'CocoaLumberjack/Swift'
  s.dependency 'SampleDynamicLibPod', '0.0.1' # you can achieve this with "#{s.name}-#{s.version.to_s}" from the 
end

关于ios - 使用 'vendored_frameworks' 和 'source_files' 用于 cocoapod 使用 'use_frameworks!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41139197/

相关文章:

iphone - 设置NSDocumentDirectory,使其不备份到iCloud

objective-c - 如何使用swift实现C-Style回调函数?

swift - 如何使用 var 扩展委托(delegate)实现的现有协议(protocol)?

javascript - 如何制作与 JS 库无关的选择器包装器?

javascript - 使用云代码和 PFFacebookUtils 覆盖电子邮件/用户名

ios - alertAction ios 的自定义标题

laravel - 试图获取非对象 Laravel 的属性(获取字符串)

php - 开发富 Web 应用程序的最佳框架是什么?

ios - 将正数转换为负数 - iOS

swift - JWT 验证算法 RSA 256 总是出错