How to build an iOS framework with weak-linked CocoaPods libraries

后端 未结 2 2004
面向向阳花
面向向阳花 2021-02-07 11:32

I am trying to build an iOS Framework (Test.framework) using the new template offered by Xcode 6 for creating Cocoa Touch Frameworks. The framework has different dependencies (a

相关标签:
2条回答
  • 2021-02-07 12:11

    The post_install code below goes at the bottom of your Podfile. It allows you specify which targets you want and the frameworks that will be weak linked. We are able to utilize this to weaklink a Framework inside our Dynamic Framework Target but continue to have it linked correclty when compiling our core application.

    targets_to_weaklink=['Target1']
    frameworks_to_weaklink=['Framework1']
    post_install do |installer|
      targets_to_weaklink.map!{|t| t="Pods-#{t}"}
      installer.pods_project.targets.each do |target|
        next unless targets_to_weaklink.include?(target.name)
    
        target.build_configurations.each do |config|
          base_config_reference = config.base_configuration_reference
          unless base_config_reference.nil?
            xcconfig_path = base_config_reference.real_path
            xcconfig = File.read(xcconfig_path)
            frameworks_to_weaklink.each do |framework|
              xcconfig = xcconfig.gsub(/-framework "#{framework}"/, "-weak_framework \"#{framework}\"")
            end
            File.open(xcconfig_path, "w") { |file| file << xcconfig }
          end
        end
      end
    end
    
    0 讨论(0)
  • 2021-02-07 12:14

    I can not comment yet so I will answer here. I think you can not do that. Cocoapods create a static library not a dynamic one so all the code should be there when you compile and is embedded in your framework.

    Cocoapods documentation, go to "What is happening behind the scenes?" for a detail explanation

    If you want to put together some basic configuration for some of your usual pods probably the best way to go is making a custom cocoapod with the other ones as dependencies. That way you can rely in cocoapods to manage versions and have the code updated per your preferences. I am using a similar approach myself and I am quite happy with the results.

    0 讨论(0)
提交回复
热议问题