marist
marist

Reputation: 71

Add a framework to "link to binary with libraries" using xcodeproj

I'm currently struggling with Xcodeproj to be able to add some libraries and change a few details in my Xcode project. I'm pretty new to Ruby and usually only use Xcode to compile my projects so here's where I am currently, trying to add CoreTelephony.framework so it appears in "link to binary with libraries" if i open the project in Xcode...

require 'rubygems'
require 'Xcodeproj'

buildPath = '/Users/matth/Desktop/buildiOS/'
origName = 'Unity-iPhoneOrig.xcodeproj'
destName = 'Unity-iPhoneMod.xcodeproj'

project = Xcodeproj::Project.new(buildPath + origName)
project::Object::AbstractTarget::add_system_framework("CoreTelephony.framework")
project.save(buildPath + destName)

... and it doesn't work, of course. If someone could give me a hand so I get started, it would be much appreciated!

Upvotes: 1

Views: 2505

Answers (1)

marist
marist

Reputation: 71

Ok, I found some interesting examples on gist

Here's a relevant one, works perfectly :

def add_system_frameworks(project, names, optional = false)
    project.targets.each do |target|
        next unless TARGET == target.name

        build_phase = target.frameworks_build_phase
        framework_group = project.frameworks_group

        names.each do |name|
            next if exist_framework?(build_phase, name)
            path = "System/Library/Frameworks/#{name}.framework"
            file_ref = framework_group.new_reference(path)
            file_ref.name = "#{name}.framework"
            file_ref.source_tree = 'SDKROOT'
            build_file = build_phase.add_file_reference(file_ref)
            if optional
                build_file.settings = { 'ATTRIBUTES' => ['Weak'] }
            end
        end
    end
end

Upvotes: 5

Related Questions