Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand correctly, you are trying to provide a font with your Cocoapod, and you intent the iOS apps which include the pod to be able to use your custom font.</p> <p>This <code>post_install</code> hook seems to work:</p> <pre><code>Pod::Spec.new do |s| # ... s.resources = "Resources/*.otf" # ... s.post_install do |library_representation| require 'rexml/document' library = library_representation.library proj_path = library.user_project_path proj = Xcodeproj::Project.new(proj_path) target = proj.targets.first # good guess for simple projects info_plists = target.build_configurations.inject([]) do |memo, item| memo &lt;&lt; item.build_settings['INFOPLIST_FILE'] end.uniq info_plists = info_plists.map { |plist| File.join(File.dirname(proj_path), plist) } resources = library.file_accessors.collect(&amp;:resources).flatten fonts = resources.find_all { |file| File.extname(file) == '.otf' || File.extname(file) == '.ttf' } fonts = fonts.map { |f| File.basename(f) } info_plists.each do |plist| doc = REXML::Document.new(File.open(plist)) main_dict = doc.elements["plist"].elements["dict"] app_fonts = main_dict.get_elements("key[text()='UIAppFonts']").first if app_fonts.nil? elem = REXML::Element.new 'key' elem.text = 'UIAppFonts' main_dict.add_element(elem) font_array = REXML::Element.new 'array' main_dict.add_element(font_array) else font_array = app_fonts.next_element end fonts.each do |font| if font_array.get_elements("string[text()='#{font}']").empty? font_elem = REXML::Element.new 'string' font_elem.text = font font_array.add_element(font_elem) end end doc.write(File.open(plist, 'wb')) end end </code></pre> <p>The hook finds the user project, and in the first target (you probably can complete this solution by asking CocoaPods to give you the real target) it looks for its <code>Info.plist</code> file(s) (normally there is only one). Finally it looks for the <code>UIAppFonts</code> key of the file, creates it if not found, and fill the array with the font names if they are not already there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload