ioscocoapodsios8-share-extensionios-targets

Only use subset of pods for child target


Is there a way to only use a subset of pods for a child target of an app (e.g. a share extension of my app)

I tried doing it this way:

platform :ios, '8.0'
inhibit_all_warnings!
I18n.enforce_available_locales = false

def all_pods
    pod 'AFNetworking', '~> 2.3'
    pod 'AFNetworkActivityLogger', '~> 2.0.2'
    pod 'TPKeyboardAvoiding', '~> 1.2.3'
    pod 'SMPageControl', '~> 1.2'
    pod 'MLPAutoCompleteTextField', :git => 'https://github.com/EddyBorja/MLPAutoCompleteTextField.git', :branch => 'master'
    pod 'UIImage-Resize', '~> 1.0.1'
    pod 'M13BadgeView', '~> 1.0.0'
    pod 'CWStatusBarNotification', '~> 2.3.3'
end

target 'Lohi Connect' do
    all_pods
    target 'Lohi Connect Share' do
       pod 'MLPAutoCompleteTextField', :git => 'https://github.com/EddyBorja/MLPAutoCompleteTextField.git', :branch => 'master'
    end
end

however when I try to build my app it appears that all pods are used for the share extension which leads to crashes because some pods use [UIApplication sharedApplication] which is not available in share extension


Solution

  • You have to end the instance of one target before assigning the second target.

    please replace above code by the following:

    platform :ios, '8.0'
    inhibit_all_warnings!
    I18n.enforce_available_locales = false
    
    def all_pods
        pod 'AFNetworking', '~> 2.3'
        pod 'AFNetworkActivityLogger', '~> 2.0.2'
        pod 'TPKeyboardAvoiding', '~> 1.2.3'
        pod 'SMPageControl', '~> 1.2'
        pod 'MLPAutoCompleteTextField', :git => 'https://github.com/EddyBorja/MLPAutoCompleteTextField.git', :branch => 'master'
        pod 'UIImage-Resize', '~> 1.0.1'
        pod 'M13BadgeView', '~> 1.0.0'
        pod 'CWStatusBarNotification', '~> 2.3.3'
    end
    
    target 'Lohi Connect' do
        all_pods
    end
    target 'Lohi Connect Share' do
           pod 'MLPAutoCompleteTextField', :git => 'https://github.com/EddyBorja/MLPAutoCompleteTextField.git', :branch => 'master'
    end